我在一个带有3个表的表单中使用了cocoon和嵌套字段,如此db方案所示:)

我想添加一个新菜单,因此在a menus/new.html.erb中我有:
<%= simple_form_for @menu do |f| %>
<%= f.input :name, label: "name", label_method: :name, value_method: :id, include_blank: true %>
<h3>Portions</h3>
<div id='portions'>
<%= f.simple_fields_for :portions do |portion| %>
<%= render 'portion_fields', :f => portion %>
<% end %>
<div class='links'>
<%= link_to_add_association 'add portion', f, :portions %>
</div>
</div>
<%= f.submit 'valider' %>
<% end %>在我的partial中,嵌套字段为_portion_fields.html.erb:
<div class='nested-fields'>
<%= f.association :aliment, label: "Intitulé de l'aliment", label_method: :label, value_method: :id, include_blank: true %>
<%= f.input :portion_qty, label: "Qté", placeholder:"portions", as: :integer %>
<%= link_to_remove_association "remove portion", f %>
</div>和我的模型:
class Menu < ApplicationRecord
has_many :portions, dependent: :destroy
has_many :aliments, through: :portions, dependent: :destroy
accepts_nested_attributes_for :portions, reject_if: :all_blank, allow_destroy: true
end
class Aliment < ApplicationRecord
has_many :portions
has_many :menus, through: :portions, dependent: :destroy
end
class Portion < ApplicationRecord
belongs_to :aliment, foreign_key: :aliment_id
belongs_to :menu, foreign_key: :menu_id
end这个错误告诉我:

发布于 2020-03-05 02:09:19
link_to_remove_association助手(Cocoon::ViewHelpers)从cocoon railtie加载到应用程序启动,如果您在gem安装后没有重新启动应用程序服务器,则可能会发生此错误(也要执行spring stop以确保)。
https://stackoverflow.com/questions/60529848
复制相似问题