cocoon icon indicating copy to clipboard operation
cocoon copied to clipboard

undefined local variable or method `form' for #<#<Class:0x00007fc295dd38d0>:0x00007fc2969e7338>

Open sidhunavroop opened this issue 8 years ago • 6 comments

_form.html.erb

<%= form_for(@parent, :html => {class: "form-horizontal", role: "form"}) do |form| %>
    <%= form.label :parent_1_firstname %>
  </div>
  <div class="col-sm-8">
    <%= form.text_field :parent_1_firstname, class: "form-control", placeholder: "Parent 1 first name", autofocus:true %>
  </div>
</div>
   <div class = "form-group">
    <div class="control-label col-sm-2">
         <%= form.label :parent_1_lastname %>
       </div>
       <div class="col-sm-8">
         <%= form.text_field :parent_1_lastname, class: "form-control", placeholder: "Parent 1 last name", autofocus:true %>
     </div>
    </div>

    <div id = 'secondaryparents'>
    <%= form.fields_for :secondaryparents do |builder| %>
    <%= render 'secondaryparent_fields', :form => builder %>
    <% end %>
    <%= link_to_add_association 'Add Secondary Parent', form, :secondaryparents %>
  </div>   
  <div class = "form-group">
    <div class="control-label col-sm-2">
    <%= form.label :address %>
  </div>
  <div class="col-sm-8">
    <%= form.text_area :address, class: "form-control", placeholder: "Address", autofocus:true %>
  </div>
</div>
<div class="col-sm-8">
    <%= form.text_area :address, class: "form-control", placeholder: "Address", autofocus:true %>
  </div>
</div>

_secondaryparent_fields.html.erb

<%= form.label :parent_first_name %> <%= form.text_field :parent_first_name %>
<%= form.label :parent_last_name %> <%= form.text_field :parent_last_name %>
<%= link_to_remove_association "Remove Parent", form %>

I am facing this. Please help undefined local variable or method `form' for #<#Class:0x00007fc295dd38d0:0x00007fc2969e7338>

sidhunavroop avatar May 15 '18 14:05 sidhunavroop

Is this not the same as #495

nathanvda avatar May 15 '18 15:05 nathanvda

In the link_to_add_association you will have to specify the form_name as follows:

link_to_add_association 'Add Secondary Parent', form, :secondaryparents, form_name: 'form'

nathanvda avatar May 15 '18 15:05 nathanvda

@nathanvda thankyou so much

sidhunavroop avatar May 15 '18 15:05 sidhunavroop

Hello i got the same issue ... em i did form_name: 'form' and nothing if i put form_name: 'f' i get the same error. @nathanvda

ricardosikic avatar Dec 18 '18 21:12 ricardosikic

Hi @ricardosikic can you open a new issue with your code please?

nathanvda avatar Dec 18 '18 21:12 nathanvda

In the link_to_add_association you will have to specify the form_name as follows:

link_to_add_association 'Add Secondary Parent', form, :secondaryparents, form_name: 'form'

thanks dude

Moriort avatar Nov 15 '19 05:11 Moriort