Rails 4 cocoon pearl not working with js

I am trying to use dynamic nested cocoon form in my rails 4.1 + active-admin application. I don't get any errors, but the add / remove links don't work.

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

I missed something in the installation of the cocoon

my version of rails

 Rails 4.1

      

I added the gem "cocoon" to the gemfile and installed the package

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 is 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 generates an error but doesn't add or remove nested form fields.? can anyone help?

+3


source to share





All Articles