gpt4 book ai didi

checkbox - Rails 4.0.3 Active-Admin has_many 复选框未保存

转载 作者:行者123 更新时间:2023-12-04 00:14:06 24 4
gpt4 key购买 nike

我使用 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:[:id],
categories_attributes: [:id, :your_fields, :_update,:_create]

关于checkbox - Rails 4.0.3 Active-Admin has_many 复选框未保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22458683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com