如何在活动管理员中将复选框值保存到数据库?

时间:2017-05-18 05:31:09

标签: ruby-on-rails activeadmin

我是ruby on rails和active admin的新手,我需要创建注册费复选框。我检查时,复选框中的值未保存到数据库中。任何人都可以帮助我吗?

  form do |f|
       f.inputs do
       f.input :name, label: "Student Name"
       f.input :dob,:label => "Date of Birth"
       f.input :age,:label => "Age"
       f.input :gender, as: :radio, :label => "Gender", :collection => [ "Male", "Female"] 
       f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| ["#{v.reg_fee}"]}
    end
    f.actions
end 

1 个答案:

答案 0 :(得分:0)

从您的代码中,您正在使用array of arrays,而应该使用array of strings

所以,改变

f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| ["#{v.reg_fee}"]}

要,

f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| "#{v.reg_fee}"}



form do |f|
       f.inputs do
       f.input :name, label: "Student Name"
       f.input :dob,:label => "Date of Birth"
       f.input :age,:label => "Age"
       f.input :gender, as: :radio, :label => "Gender", :collection => [ "Male", "Female"] 
       f.input :reg_fee, :as => :check_boxes, :collection => RegChargeSetup.all.map{|v| "#{v.reg_fee}"}
    end
    f.actions
end