我有一个有问题提交的民意调查表,每个问题有4个答案是has_many关系船与答案表
class Poll < ActiveRecord::Base
has_many :answer
end
我的答案模型
class Answer < ActiveRecord::Base
belongs_to :poll, :class_name => "Poll", :foreign_key => "question_id"
end
我的有效管理表格是
form :html => {:validate => true} do |f|
f.inputs "Polls" do
f.input :question
f.has_many :answer, :sortable => :priority do |ff|
ff.input :question[]
end
f.input :status,as: 'hidden',:input_html => { :value => f.object.status.present? ? f.object.status : 'Unpublished' }
f.input :position,as: 'hidden',:input_html => { :value => Poll.count().to_i + 1}
end
f.actions
end
我想在我的表单中只显示4个答案文本框,我该怎么做
答案 0 :(得分:0)
将以下内容添加到您的民意调查控制器 -
def new
@poll = Poll.new
4.times do
@poll.answers.build
end
end