Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sidhunavroop opened this issue May 15, 2018 · 6 comments

Comments

@sidhunavroop
Copy link

sidhunavroop commented May 15, 2018

_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>

@nathanvda
Copy link
Owner

Is this not the same as #495

@nathanvda
Copy link
Owner

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'

@sidhunavroop
Copy link
Author

@nathanvda thankyou so much

@ricardosikic
Copy link

ricardosikic commented Dec 18, 2018

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

@nathanvda
Copy link
Owner

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

@Moriort
Copy link

Moriort commented Nov 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants