AjaxNestedForm
This gem provides adding and removing nested model fields dynamically through JavaScript using jQuery. It may using for Rails 3.1+ with assets pipeline
Installation
Add this line to your application's Gemfile:
gem 'ajax_nested_form'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ajax_nested_form
Usage
Javascript
Add necessary javascript file to app/assets/javascripts/application.js
//= require ajax_nested_form
Using ActionView helper methods
For creating link to add nested model fields use next syntax
link_to_add_fields "LinkText", form_builder_instance, :association_name, "container_for_adding_fields", "position_for_adding"
Available positions for adding are "first" and "last". Last is used by default.
Sample
link_to_add_fields "Add list", f, :lists, "#lists-container", "first"
For creating link to destroy nested model fields use following code
link_to_remove_fields "Remove", form_builder_instance, "nested_model_fields_container"
Sample
link_to_remove_fields "Remove", f, ".list-fields"
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request