1
我试图建立一个标准的关系如下:轨道4有许多通过与主动管理
class Category < ActiveRecord::Base
has_many :post_categories
has_many :posts, :through => :post_categories
accepts_nested_attributes_for :post_categories
end
class Post < ActiveRecord::Base
has_many :post_categories
has_many :categories, :through => :post_categories
accepts_nested_attributes_for :post_categories
attr_accessor :category_ids
end
class PostCategory < ActiveRecord::Base
belongs_to post
belongs_to category
end
我使用ActiveAdmin和需要设置复选框来描述这种关系。 我已经尝试了许多不同的方法来保存复选框。这里是我的管理post.rb文件:
ActiveAdmin.register Post do
permit_params :content, category_ids: []
form do |f|
f.inputs # Include the default inputs
f.inputs "Categories" do
f.input :categories, as: :check_boxes, collection: Category.all
end
f.actions # Include the default actions
end
end
我已经尝试了不同的许可证PARAMS如
permit_params :content, :categories
permit_params :content, post_categories_attributes: [:id, :post_id, :category_id]
permit_params :content, category_ids: [:id]
数据库设置如图所示的轨道教程,和关系似乎在其他地方工作除了从activeadmin保存。我甚至试图用param.permit!
来允许所有参数,但仍然没有运气。
我发现许多看似相同的问题,但很多人给出不同的答案,似乎没有任何工作。
出了什么问题?
http://stackoverflow.com/a/24486212/3199803此解决方案有效,但似乎应该有一个更简洁的方法。 对于同一个问题的其他解决方案不适合我。 – BreadnButter 2014-09-28 22:34:53
创建操作开始时日志文件中的内容是什么? – nistvan 2014-09-29 11:44:08