Question

i am trying to use cocoon for nested ajax form coupled with formtastic

my rails version

 Rails 3.2.3

i have put gem "cocoon" im my gemfile and did a bundle install

then in my elements/_form.html.erb:

 <%= 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 generate no error but do not display the nested link or form

i then added to assets/application.js:

   //= require cocoon

and to layout/application.html.erb

          <%= javascript_include_tag :cocoon %>

this generate the error :

        couldn't find file 'cocoon'

did i miss something in cocoon installation ? could anyone help?

Was it helpful?

Solution

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

= javascript_include_tag "application"

and not the :cocoon (that is only for older rails 3.0.x). The application.js will contain the cocoon javascript files automatically (asset pipeline).

Hope this helps.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top