我的模特:
class Poll < ActiveRecord::Base
validates_presence_of :title
validates_presence_of :description
has_many :questions, dependent: :destroy
has_many :responses, through: :questions
accepts_nested_attributes_for :questions, reject_if: lambda { |a| a[:title].blank? }, allow_destroy: true
end
class Question < ActiveRecord::Base
belongs_to :poll
has_many :answers, dependent: :destroy
has_many :responses, through: :answers
accepts_nested_attributes_for :answers, reject_if: lambda { |a| a[:content].blank? }, allow_destroy: true
end
class Answer < ActiveRecord::Base
belongs_to :question
has_many :responses
end
class Response < ActiveRecord::Base
belongs_to :answer
end
当你转到/polls/.:id
时,它会显示民意调查及其相应的问题以及每个问题及其相应的答案。
我一直在玩this answer,但我不知道该怎么做。我希望我发送一个民意调查链接(/polls/.:id)以便能够回答该民意调查。之前链接的答案中描述的方法为每个问题创建一个表单。
答案 0 :(得分:1)
我在这里查看有关rails视图的文档: http://guides.rubyonrails.org/action_view_overview.html
有大量关于如何使用各种表单元素访问和传输数据的文档。