gpt4 book ai didi

ruby-on-rails - Formtastic 有很多关联

转载 作者:行者123 更新时间:2023-12-02 03:37:01 27 4
gpt4 key购买 nike

我有一个 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

事件类别:

class CampaignCategory < ActiveRecord::Base
attr_accessible :campaign_id, :category_id
belongs_to :campaign
belongs_to :category
end

我在 Activeadmin 的 campaigns.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

类别在多选框中正确显示。但是我在提交表单时收到以下错误: 无法批量分配 protected 属性:category_ids

我尝试在 Campaign 中调用 accepts_nested_attributes_for :categories,但这没有用。我该如何解决这个问题?谢谢。

最佳答案

在 Campaign 模型中将 :category_ids 添加到您的 attr_accessible 调用应该可以做到这一点

关于ruby-on-rails - Formtastic 有很多关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22746847/

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