【发布时间】:2014-03-30 16:54:31
【问题描述】:
我有一个 Campaign 模型和一个 Category 模型。他们彼此之间有一种“多次通过”的关系。中间模型是campaign_categories。 广告系列:
class Campaign < ActiveRecord::Base
attr_accessible :name, :carousel_image, :show_in_carousel, :title, :carousel_description,
:video_embed_code, :goal, :end_date, :backer_count, :author_name, :author_photo,
:author_description_md, :author_description_html, :description_markdown, :description_html,
:funds_description_md, :funds_description_html, :campaign_status_id
#associations
has_many :campaign_categories
has_many :categories, through: :campaign_categories
结束
类别:
class Category < ActiveRecord::Base
attr_accessible :name
#associations
has_many :campaign_categories
has_many :campaigns, through: :campaign_categories
end
Campaign_Category:
class CampaignCategory < ActiveRecord::Base
attr_accessible :campaign_id, :category_id
belongs_to :campaign
belongs_to :category
end
我在活动管理员的活动.rb 中有以下内容:
ActiveAdmin.register Campaign do
form :html => { :enctype => 'multipart/form-data'} do |f|
f.inputs "Campaign Basic Information" do
f.input :name
f.input :categories
end
f.actions
end
end
类别在多选框中正确显示。但我在提交表单时收到以下错误: 无法批量分配受保护的属性:category_ids
我尝试在 Campaign 中调用 Accepts_nested_attributes_for :categories,但这不起作用。我该如何解决这个问题?谢谢。
【问题讨论】:
标签: ruby-on-rails activeadmin formtastic