Skip to content

Commit

Permalink
Merge branch 'formbuilders'
Browse files Browse the repository at this point in the history
Conflicts:
	README.rdoc
  • Loading branch information
fxposter committed Jun 29, 2011
2 parents 0a09783 + d5b4838 commit d72080c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
31 changes: 11 additions & 20 deletions README.rdoc
Expand Up @@ -6,25 +6,8 @@ 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

For some reasons, in this fork the main branch is now 'unstable'. In order to use this branch in your projects - the following line in Gemfile should look like this:

gem 'nested_form', :git => 'git://github.com/fxposter/nested_form.git', :branch => 'unstable'

=== Simple Form and Formtastic support

Now if you add

gem 'simple_form'

or

gem 'formtastic'

you will be able to use simple_nested_form_for and semantic_nested_form_for respectively.

Formtastic is supported only with Rails 3.0, Rails 3.1 integration is not available now.
== Changes in this repo

=== Enhanced jQuery javascript template

Expand All @@ -40,6 +23,9 @@ There's a small fix for Rails 3.1 form handling.
Also support of Rails 3.1 led me to huge refactor of specs setup (now using Helper specs from rspec-rails instead of custom implementation spec context).
Last, but not least - I used appraisal[https://github.com/thoughtbot/appraisal] gem to run specs for rails 3 and 3.1.

Formtastic is supported only with Rails 3.0, Rails 3.1 integration is not available now.


== Setup

Add it to your Gemfile then run +bundle+ to install it.
Expand Down Expand Up @@ -74,6 +60,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

Use <tt>simple_nested_form_for</tt> or <tt>semantic_nested_form_for</tt> for SimpleForm and Formtastic support respectively. This is feature is not yet in a Gem release but is in the Git repo.


== 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 @@ -90,10 +81,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
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
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
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
_view.simple_nested_form_for(Project.new) do |f|
f.should be_instance_of(NestedForm::SimpleBuilder)
Expand Down

0 comments on commit d72080c

Please sign in to comment.