Installing / using cocoon gem?

I am trying to use cocoon for ajax nested form in combination with formtastic

my rails version

Rails 3.2.3 

I put the cocoon gem in my gemfile and installed the package

then in my /_form.html.erb elements:

  <%= semantic_form_for @element do |f| %> <%= f.inputs do %> <%= f.input :projects, :label_method => :projectname%> <%= f.semantic_fields_for :experiments do |exp| %> <% render 'experiment_fields', :f => exp %> <%= link_to_add_association "Add experiment", f, :experiments%> <%end%> <% end %> <%= f.actions :submit, :cancel %> <% end %> 

with elements /_experiment_fields.html.erb:

  <div class='nested-fields'> <%= f.input :exptype %> <%= link_to_remove_association "remove experiment", f %> </div> 

this does not cause an error, but does not display a sublink or form

i is then added to assets / application.js:

  //= require cocoon 

and in layout / application.html.erb

  <%= javascript_include_tag :cocoon %> 

this generates an error:

  couldn't find file 'cocoon' 

Did I miss something in the installation of the cocoon? can anyone help?

+4
source share
2 answers

In layout/application.html.erb you should just write

 = javascript_include_tag "application" 

and not :cocoon (i.e. only for old rails 3.0.x). application.js will contain coconut javascript files automatically (resource pipeline).

Hope this helps.

+1
source

I just got this error after adding // = I need a cocoon for the asset pipeline before restarting my rails server. Obviously, you probably restarted the rails server at this point, but for the sake of anyone else with this error, try restarting the rails.

+11
source

All Articles