Im starting off with Rails and was trying to implement a basic Q & A website. One question has many answers.
How do I create a new question that attaches to an existing answer?
All the available tutorials on 开发者_Python百科the web are for nested forms, which is not what im looking for. The question already exists. I just want to attach new answers to it.
Any help much appreciated!
I think you can do this so.
class Question < ActiveRecord::Base
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
end
Routes:
resources :questions do
resources :answers
end
Here: /questions/1/answers/new
Controller: Answer
Action: new
return an HTML form for creating a new ad belonging to a specific question
POST /questions/1/answers
create create a new ad belonging to a specific question
http://guides.rubyonrails.org/routing.html#nested-resources
https://github.com/rusak1 - send a letter for me here
精彩评论