Error during cocoon implementation

0

I have a model Describete that is associated with a user. In the same view of describe there should be a 'add more' button, but it does not appear. Having the following error:

  

undefined local variable or method 'form'

if I change it to f it will tell me to change it to form.

Following the documentation I have done the following steps.

for _describetes_fields.html :

  <div class="field">
    <%= f.label :perfil %>
    <%= f.text_area :perfil %>
  </div>

  <div class="field">
    <p>¿En que te capacitaste?</p>
    <%= f.text_field :carrera %>
  </div>

  <div class="field">
    <p>Ins.text_field :centro %>
  </div>

  <div class="field">
    <p>Año de tu capacitacion</p>
    <%= f.text_field :year %>
  </div>

  <%= link_to_remove_association 'delete', f %>

for _form.html (from describete view):

<%= form_with(model: describete, local: true) do |form| %>
  <% if describete.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(describete.errors.count, "error") %> prohibited this describete from being saved:</h2>

      <ul>
      <% describete.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <p>Perfil profesional</p>
    <%= form.text_area :perfil %>
  </div>

  <div class="field">
    <p>¿En que te capacitaste?</p>
    <%= form.text_field :carrera %>
  </div>

  <div class="field">
    <p>Institucion o centro de capacitacion</p>
    <%= form.text_field :centro %>
  </div>

  <div class="field">
    <p>Año de tu capacitacion</p>
    <%= form.text_field :year %>
  </div>

  <h3>Mas</h3>
  <%= form.fields_for :describetes do |describete| %>
   <%= render 'describetes_fields', :form => describete %>
  <% end %>

  <div>
    <%= link_to_add_association 'Add more', form, :describetes, :partial => 'describetes/describetes_fields' %>
  </div>


  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

and my model describete.rb :

class Describete < ApplicationRecord
    belongs_to :user

    has_many :describetes
    belongs_to :describete

    accepts_nested_attributes_for :describetes, reject_if: :all_blank, allow_destroy: true

end
    
asked by ricardo leiva sikic 16.12.2018 в 20:19
source

1 answer

1

The error message is confusing, however I can see the problem in your code right on this line:

<%= render 'describetes_fields', :form => describete %>

You are using form when you should use f , since the partial uses f (this is the default behavior of Cocoon '):

<%= render 'describetes_fields', :f => describete %>
    
answered by 18.12.2018 в 18:47