2
我正在通過在活動管理中創建一個has_many:through關係來工作。下面是模型因爲他們的立場:ActiveAdmin has_many通過關係不更新param Rails
class Category < ActiveRecord::Base
has_many :subcategories
end
class Subcategory < ActiveRecord::Base
has_many :product_in_subcategories
has_many :products, through: :product_in_subcategories
accepts_nested_attributes_for :product_in_subcategories, :allow_destroy => true
belongs_to :category
end
class Product < ActiveRecord::Base
has_many :product_in_subcategories
has_many :subcategories, through: :product_in_subcategories
accepts_nested_attributes_for :product_in_subcategories, :allow_destroy => true
end
class ProductInSubcategory < ActiveRecord::Base
belongs_to :product
belongs_to :subcategory
end
在ActiveAdmin我有permit_params,形成像這樣:
ActiveAdmin.register Product do
# note some params that are product only have been removed for simplicity
permit_params :name, subcategory_id:[:id], product_in_subcategories_attributes: [:id, :subcategory_id, :product_id, :_create, :_update]
form do |f|
f.inputs
f.has_many :product_in_subcategories do |s|
s.input :subcategory_id, :as => :check_boxes, :collection => Subcategory.all
end
f.actions
end
end
形式填充爲應,拯救一切除了subcategory_id。如果我在數據庫中輸入了一個合適的子類別標識,那麼該框會顯示在編輯時檢查。
節省給予時消息:
Unpermitted parameters: subcategory_id
然而,似乎它試圖與產品,對此沒有一個subcategory_id提交此。關於我在這裏做錯了什麼的想法?這讓我瘋狂,我已經閱讀了所有我能找到的東西。我真的很想明白我做錯了什麼。謝謝。
任何解決方案與複選框? –
說實話,我推出了自己的寶石,這樣管理員就可以快速和無需DSL定製。你可以在[SkinnyAdmin](https://www.skinnyadmin.org)找到它。 ActiveAdmin沒什麼問題,但DSL對我來說很頭疼。 – user1572597