Rails Activeadmin:未保存复选框值
Rails Activeadmin : Check boxes values are not saved
型号
# certification.rb
class Certification < ActiveRecord::Base
extend Enumerize
enumerize :certification_type, in: [:SEO, :CRM]
end
我的管理文件
# admin/certification.rb
ActiveAdmin.register Certification do
permit_params :name,
:certification_type,
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Certifications" do
f.input :name, :label => 'Nom'
f.input :certification_type, :label => 'Type',
as: :check_boxes
end
f.actions
end
end
问题出在 certification_type
字段。
当我在我的 activeadmin 页面中勾选一种类型时,该条目不会保存在数据库中。但是当我将 as: :check_boxes
更改为 as: :select
时,它起作用了。
你知道有什么原因吗?
谢谢
您不能在此处使用复选框,因为复选框允许一个字段 select 多个值,但您没有在 enumerize
上指定 multiple: true
(因为您没有我猜需要这个)。所以你应该使用单选按钮,因为它们只允许 select 许多值中的一个(类似于 select
)。
尝试将 as: :check_boxes
更改为 as: :radio
:
f.input :certification_type, :label => 'Type', as: :radio
型号
# certification.rb
class Certification < ActiveRecord::Base
extend Enumerize
enumerize :certification_type, in: [:SEO, :CRM]
end
我的管理文件
# admin/certification.rb
ActiveAdmin.register Certification do
permit_params :name,
:certification_type,
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Certifications" do
f.input :name, :label => 'Nom'
f.input :certification_type, :label => 'Type',
as: :check_boxes
end
f.actions
end
end
问题出在 certification_type
字段。
当我在我的 activeadmin 页面中勾选一种类型时,该条目不会保存在数据库中。但是当我将 as: :check_boxes
更改为 as: :select
时,它起作用了。
你知道有什么原因吗?
谢谢
您不能在此处使用复选框,因为复选框允许一个字段 select 多个值,但您没有在 enumerize
上指定 multiple: true
(因为您没有我猜需要这个)。所以你应该使用单选按钮,因为它们只允许 select 许多值中的一个(类似于 select
)。
尝试将 as: :check_boxes
更改为 as: :radio
:
f.input :certification_type, :label => 'Type', as: :radio