Skip to content

Commit

Permalink
updating readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jun 29, 2011
1 parent 17d5bd1 commit b6ab23c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
17 changes: 7 additions & 10 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ This gem only works with Rails 3. See the {rails2 branch}[https://github.com/rya

An example project showing how this works is available in the {complex-nested-forms/nested_form branch}[https://github.com/ryanb/complex-form-examples/tree/nested_form].

== Changes in this repo

Added simple_form support. Now if you add

gem 'simple_form'

before adding this gem to your Gemfile - nested_form_for will use SimpleForm builder instead of default ActionView builder.

== Setup

Add it to your Gemfile then run +bundle+ to install it.
Expand Down Expand Up @@ -48,6 +40,11 @@ You will then be able to use +link_to_add+ and +link_to_remove+ helper methods o
<p><%= f.link_to_add "Add a task", :tasks %></p>


== SimpleForm and Formtastic Support

If you add <tt>simple_form</tt> or <tt>formtastic</tt> before <tt>nested_form</tt> in your Gemfile it will automatically use that given form builder when calling <tt>nested_form_for</tt>.


== Partials

It is often desirable to move the nested fields into a partial to keep things organized. If you don't supply a block to fields_for it will look for a partial and use that.
Expand All @@ -64,10 +61,10 @@ If you are using jQuery, <tt>nested:fieldAdded</tt> and <tt>nested:fieldRemoved<

== Special Thanks

First of all, thanks ro Ryan Bates for this gem. Awesome work.

This gem was originally based on the solution by Tim Riley in his {complex-form-examples fork}[https://github.com/timriley/complex-form-examples/tree/unobtrusive-jquery-deep-fix2].

Thank you Andrew Manshin for the Rails 3 transition, {Andrea Singh}[https://github.com/madebydna] for converting to a gem and {Peter Giacomo Lombardo}[https://github.com/pglombardo] for Prototype support.

Andrea also wrote a great {blog post}[http://blog.madebydna.com/all/code/2010/10/07/dynamic-nested-froms-with-the-nested-form-gem.html] on the internal workings of this gem.

Thanks {Pavel Forkert}[https://github.com/fxposter] for the SimpleForm and Formtastic support.
4 changes: 2 additions & 2 deletions lib/nested_form/builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module NestedForm
class Builder < ::ActionView::Helpers::FormBuilder
include ::NestedForm::BuilderMixin
end

begin
require 'simple_form'
class SimpleBuilder < ::SimpleForm::FormBuilder
include ::NestedForm::BuilderMixin
end
rescue LoadError
end

begin
require 'formtastic'
class FormtasticBuilder < ::Formtastic::SemanticFormBuilder
Expand Down
6 changes: 3 additions & 3 deletions lib/nested_form/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ def nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::Builder)
form_for(*(args << options), &block) << after_nested_form_callbacks
end

if defined?(NestedForm::SimpleBuilder)
def simple_nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::SimpleBuilder)
simple_form_for(*(args << options), &block) << after_nested_form_callbacks
end
end

if defined?(NestedForm::FormtasticBuilder)
def semantic_nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::FormtasticBuilder)
Expand All @@ -29,7 +29,7 @@ def after_nested_form(association, &block)
@after_nested_form_callbacks << block
end
end

private
def after_nested_form_callbacks
@after_nested_form_callbacks ||= []
Expand Down
2 changes: 1 addition & 1 deletion spec/nested_form/view_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
f.should be_instance_of(NestedForm::Builder)
end
end

it "should pass instance of NestedForm::SimpleBuilder to simple_nested_form_for block" do
@template.simple_nested_form_for(Project.new) do |f|
f.should be_instance_of(NestedForm::SimpleBuilder)
Expand Down

0 comments on commit b6ab23c

Please sign in to comment.