ActiveAdmin ::使用 has_many 关系在活动管理员中显示 4 个文本框
ActiveAdmin ::Show 4 textbox in active admin using has_many relationship
我有一个投票 table 已提交问题,每个问题有 4 个答案,即 has_many 与答案 table
的关系
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 个答案文本框,我该怎么做
将以下内容添加到您的投票控制器-
def new
@poll = Poll.new
4.times do
@poll.answers.build
end
end
我有一个投票 table 已提交问题,每个问题有 4 个答案,即 has_many 与答案 table
的关系 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 个答案文本框,我该怎么做
将以下内容添加到您的投票控制器-
def new
@poll = Poll.new
4.times do
@poll.answers.build
end
end