Can't use the nested_form_for gem

3.1k views Asked by At

I am using the nested_form_for gem for the first time. I don't know if this is an issue or if I am using it wrong, but I am getting an "undefined method nested_form_for" error. I have a pretty regular form as you can see:

  <%= nested_form_for @user do |f| %>
        <%= f.fields_for :godfathers do |godfather_form| %>
            <%=  godfather_form.label :name %> <br/>
            <%=  godfather_form.text_field :name %> <br/>
            <%=  godfather_form.label :description %> <br/>
            <%=  godfather_form.text_field :description %> <br/>
            <%=  godfather_form.link_to_remove "Remove this godfather" %>
        <% end %>
       <%= f.link_to_add "Add a godfather", :godfathers %>
   <% end %>

By the way, I installed the gem and ran the: rails generate nested_form:install command to generate the nested_form.js file that I included in my layout after the jquery inclusion(<%= javascript_include_tag :default, 'nested_form' %>).

Anyone using this gem as well?

Thanks!

1

There are 1 answers

1
Mat Schaffer On BEST ANSWER

Everything looks right and if the generator ran the gem should be in place. Have you restarted your server since adding the plugin to your Gemfile?