3

I have trying to use cocoon dynamically nested form in my rails 4.1 + active-admin application. am not getting any errors but the add / remove links are not working.

when i checked in the browser with firebug the cocoon.js is not included with my application.

did i miss something in cocoon installation

my rails version

 Rails 4.1

i added gem "cocoon" in gemfile and done bundle install

added assets/application.js:

   //= require cocoon

then in my lease_informations/new.html.erb:

 <div>
  <%= semantic_form_for [:admin, @lease_information] do |f| %>
    <%= render 'form', f: f %>
    <center>
      <%= f.actions do %>
        <%= f.action :submit, label: "Save" %>
        <li class="cancel"> 
          <%= link_to :cancel, admin_employees_path %> 
        </li>
      <% end %>
    </center>
  <% end %>
</div>

in _form.html.erb am rendering _lease_units.html.erb

with lease_informations/_lease_units.html.erb :

<div id='lease_units'>
  <%= f.semantic_fields_for :lease_units do |lease_unit| %>
    <%= render 'lease_unit_fields', :f => lease_unit %>
  <% end %>
  <div class='links'>
    <%= link_to_add_association 'Add Units', f, :lease_units %>

  </div>
</div>

with lease_informations/_lease_unit_fields.html.erb :

<div class='nested-fields'>
  <%= f.inputs do %>
    <%= f.input :unit_type %>
    <%= f.input :unit %>
    <%= f.input :floor %>
    <%= link_to_remove_association "Remove Unit", f %>
  <% end %>
</div>

my model lease_information.rb

class LeaseInformation < ActiveRecord::Base
  has_many  :lease_units
  has_many  :lease_contacts 

  belongs_to  :lease_type
  belongs_to  :sales_category

  accepts_nested_attributes_for :lease_units, :reject_if => :all_blank, :allow_destroy => true
end

this generate no error but not adding or removing nested form fields.? could anyone help?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Mani David
  • 1,382
  • 1
  • 14
  • 30
  • 2
    You mention the error yourself: if `cocoon.js` is not included in the browser then it can never work. You did all the correct steps, I am guessing either your browser is using a cached version of application.js or you compiled your assets, so you will have to recompile them. Note: never use precompiled assets in development, it is such a pain. – nathanvda Jan 09 '15 at 12:20

0 Answers0