Вложенные поля - RoR - link_to_add_associations - PullRequest
0 голосов
/ 04 марта 2020

Я использую кокон и вложенные поля в форме с 3 таблицами, как показано на схеме БД :) enter image description here Я хочу добавить новое меню в меню / 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 %>

в моем партиале для вложенных полей _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

ошибка говорит мне, что:

enter image description here

1 Ответ

0 голосов
/ 04 марта 2020

link_to_remove_association помощник (Cocoon::ViewHelpers) загружается при запуске приложения из cocoon railt ie, эта ошибка может произойти, если вы не перезапустили свой сервер приложений после установки gem (также убедитесь, что вы сделали spring stop) .

...