Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 5f8969ca9134f6ec0c3b72a48aaa7fed8290ac01 @ryanb committed Jan 11, 2010
Showing with 109 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +42 −0 README.rdoc
  3. +13 −0 Rakefile
  4. +1 −0 init.rb
  5. +2 −0 lib/nested_form.rb
  6. +5 −0 lib/nested_form/builder.rb
  7. +5 −0 lib/nested_form/helper.rb
  8. +5 −0 spec/nested_form/builder_spec.rb
  9. +5 −0 spec/nested_form/helper_spec.rb
  10. +11 −0 spec/spec_helper.rb
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Ryan Bates
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 README.rdoc
@@ -0,0 +1,42 @@
+= Nested Form
+
+A Rails plugin to conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery.
+
+This is in early development, so much of this documentation is not yet applicable.
+
+
+== Usage
+
+When installing this plugin it will add a file at public/javascripts/nested_form.js which should be included after jQuery.
+
+ <%= javascript_include_tag 'jquery', 'nested_form' %>
+
+Now you can generate a nested form using the nested_form_for helper method.
+
+ <% nested_form_for @project do |f| %>
+
+You can use this form just like normal, including the fields_for helper method for nesting models. The benefit of this plugin comes from the link_to_add and link_to_remove helper methods on the form builder.
+
+ <% f.fields_for :tasks do |task_form| %>
+ <%= task_form.text_field :name %>
+ <%= task_form.link_to_remove %>
+ <% end %>
+ <%= f.link_to_add "Add a task", :tasks %>
+
+This generates links which dynamically add and remove fields.
+
+
+== 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.
+
+ <%= f.fields_for :tasks %>
+
+In this case it will look for a partial called "task_fields" and pass the form builder as an f variable to it.
+
+
+== Special Thanks
+
+This plugin is based on the solution by Tim Riley in his complex-form-examples fork.
+
+http://github.com/timriley/complex-form-examples/tree/unobtrusive-jquery-deep-fix2
13 Rakefile
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'rake'
+require 'spec/rake/spectask'
+
+spec_files = Rake::FileList["spec/**/*_spec.rb"]
+
+desc "Run specs"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = spec_files
+ t.spec_opts = ["-c"]
+end
+
+task :default => :spec
1 init.rb
@@ -0,0 +1 @@
+require 'nested_form'
2 lib/nested_form.rb
@@ -0,0 +1,2 @@
+require File.dirname(__FILE__) + '/nested_form/builder'
+require File.dirname(__FILE__) + '/nested_form/helper'
5 lib/nested_form/builder.rb
@@ -0,0 +1,5 @@
+module NestedForm
+ class Builder < ActionView::Helpers::FormBuilder
+
+ end
+end
5 lib/nested_form/helper.rb
@@ -0,0 +1,5 @@
+module NestedForm
+ module Helper
+
+ end
+end
5 spec/nested_form/builder_spec.rb
@@ -0,0 +1,5 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe NestedForm::Builder do
+
+end
5 spec/nested_form/helper_spec.rb
@@ -0,0 +1,5 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe NestedForm::Helper do
+
+end
11 spec/spec_helper.rb
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'spec'
+require 'active_support'
+require 'active_record'
+require 'action_controller'
+require 'action_view'
+require File.dirname(__FILE__) + '/../lib/nested_form.rb'
+
+Spec::Runner.configure do |config|
+ config.mock_with :rr
+end

0 comments on commit 5f8969c

Please sign in to comment.