Ruby on rails 嵌套字段-RoR-链接到添加关联
我正在使用cocoon和嵌套字段,其形式有3个表,如此db方案所示:) 我想添加一个新菜单,因此在menus/new.html.erb中我有:Ruby on rails 嵌套字段-RoR-链接到添加关联,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我正在使用cocoon和嵌套字段,其形式有3个表,如此db方案所示:) 我想添加一个新菜单,因此在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</h
<%= 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 %>
部分
部分%>
在嵌套字段的“我的部分”\u partition\u 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
class菜单
错误告诉我:
从Cocoon railtie在应用程序启动时加载链接到删除关联的帮助程序(Cocoon::ViewHelpers
),如果在gem安装后未重新启动应用程序服务器,则可能会发生此错误(请确保执行弹簧停止操作)