No commit activity in last 3 years
No release in over 3 years
Manage multiple models in the same form
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

NestedFieldsRails

Gem Version

Manage multiple models in the same form. Inspired on nested_form gem

Tested with Rails 3.2.x and Ruby 1.9.3

Installation

Add this line to your application's Gemfile:

gem 'nested_fields_rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nested_fields_rails

And then add it to the Asset Pipeline in the application.js file:

//= require jquery_nested_fields

Usage

Model definition

class Person
	has_many :phones
	attr_accessible :phones_attributes
	accepts_nested_attributes_for :phones, :allow_destroy => true
end

Form specification

= form_for @person do |f|
  ...
  %strong Phones
  = f.link_to_add_nested_fields 'Add', :phones
  = f.nested_fields_for :phones do |phones_form|
    = phones_form.link_to_remove_nested_fields 'Remove'
    = phones_form.text_field :number	

Partials support

Main form

= form_for @person do |f|
  ...
  %strong Phones
  = f.link_to_add_nested_fields 'Add', :phones
  = f.nested_fields_for :phones

Partial for item

= f.link_to_remove_nested_fields 'Remove'
= f.text_field :number	

Html wrappers

Table wrapper

= form_for @person do |f|
  ...
  %table
  	%thead
  	  %tr
  	    %td f.link_to_add_nested_fields 'Add', :phones
  	    %td Phones
    = f.nested_fields_for :phones, nil, :wrapper => :table do |phones_form|
      %td= phones_form.link_to_remove_nested_fields 'Remove'
      %td= phones_form.text_field :number

Custom wrapper

= form_for @person do |f|
  ...
  %strong Phones
  = f.link_to_add_nested_fields 'Add', :phones
  = f.nested_fields_for :phones, nil, :collection_wrapper => :ul, :element_wrapper => :li do |phones_form|
    = phones_form.link_to_remove_nested_fields 'Remove'
    = phones_form.text_field :number	

Order support

= form_for @person do |f|
  ...
  %strong Phones
  = f.link_to_add_nested_fields 'Add', :phones
  = f.nested_fields_for :phones do |phones_form|
    = phones_form.link_to_remove_nested_fields 'Remove'
    = phones_form.link_to_up_nested_fields 'Up'
    = phones_form.link_to_down_nested_fields 'Down'
    = phones_form.text_field :number
    = phones_form.index_nested_fields :order

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request