Permalink
Browse files

updating readme

  • Loading branch information...
1 parent 17d5bd1 commit b6ab23cb8e6aa705d2ef0541e039a27cadc5d239 @ryanb ryanb committed Jun 29, 2011
Showing with 13 additions and 16 deletions.
  1. +7 −10 README.rdoc
  2. +2 −2 lib/nested_form/builders.rb
  3. +3 −3 lib/nested_form/view_helper.rb
  4. +1 −1 spec/nested_form/view_helper_spec.rb
View
@@ -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.
@@ -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.
@@ -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,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
@@ -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)
@@ -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 ||= []
@@ -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)

0 comments on commit b6ab23c

Please sign in to comment.