I have installed this pretty looking gem and have spent the last 2 hours trying to make it work.
I manage to display nested fields within the parent form and create/update records.
However, the add/remove JS links do not work. And this is because in the console is giving me this error.
Uncaught TypeError: Object [object Object] has no method 'nestedFields' neste_attributes_forms.js:2
(anonymous function) neste_attributes_forms. js:2
fire jquery.js:1018
self.fireWith jquery.js:1128
jQuery.extend.ready jquery.js:417
DOMContentLoaded
I am pretty new in JS. So, I am not sure what the problem is.
I have tried the same code it says on the gem page:
$(document).ready(function(e) {
$('FORM').nestedFields();
});
I have also tried calling by the id of the div. But, to not avail. I have check the page source and it loads this piece of code.
Do you have any idea what I am missing? any help much appreciated!!!
The piece of the form: haml
= form_for(@event) do |f|
....somefields....
#nested_layers
.items
= f.nested_fields_for :details do |f|
%fieldset.item
= f.label :town
= f.text_field :town
%a.remove{:href => "#"} remove
= f.hidden_field :id
= f.hidden_field :_destroy
%a.add{:href => "#"} add phone
..someOtherFields....
application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui-1.9.2.custom.min
//= require jquery.nested-fields
....
FIXED: Application.js contains a really clever sentence that one should not delete: // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. So just make sure every //= require... is right below another. Otherwise you will miss methods!!
//= require jquery.nested-fields
toapp/assets/javascripts/application.js
– ted