【发布时间】:2014-04-22 21:54:51
【问题描述】:
我使用 rails 4.0.3 并尝试在 Active-Admin 中设置多对多的复选框。未保存复选框选择。这就是我所拥有的
class Product < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
accepts_nested_attributes_for :categorizations
end
class Category < ActiveRecord::Base
has_many :categorizations
has_many :products, :through => :categorizations
accepts_nested_attributes_for :categorizations
end
class Categorization < ActiveRecord::Base
belongs_to :category
belongs_to :product
end
ActiveAdmin.register Product do
permit_params :title, :price, category_ids:[:id]
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Product" do
f.input :title
f.input :price
f.input :categories, :as => :check_boxes
end
f.actions
end
end
我也尝试过使用 has_and_belongs_to_many 但仍然无法保存选择。
任何指导将不胜感激。
干杯
【问题讨论】:
-
我想通了。它应该是 permit_params :title, :price, :category_ids => []
-
您应该将其发布为答案并接受它
标签: checkbox ruby-on-rails-4 activeadmin has-many-through