Rails: Can't access questions associated with answers? -
i error undefined method `question_answers_path' line of code @question.answers
i have answers belong_to question, questions has_many answers, , have added migration answers rails g migration add_question_id_to_answers question_id: integer
i've ran db:migrate, can't figure out why method undefined.
code
i render <%= @question.answers % , in answer file
<%= answer.answer %>
my answer migration add_question_id looks this
class addquestionidtoanswer < activerecord::migration def change add_column :answers, :question_id, :integer add_index :answers, :question_id end end
my question looks
class question < activerecord::base has_many :answers attr_accessible :query, :text validates :query, presence: true end
my answer looks this
class answer < activerecord::base has_many :comments, dependent: :destroy belongs_to :question attr_accessible :anonymous, :answer, :commenter, :votes end
have defined route in config/routes.rb
? specifically, have nested answers inside questions?
something like:
resources :questions resources :answers end
you might try rake routes | grep answers
command line see if route exists.
Comments
Post a Comment