nested_form 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG.rdoc +12 -0
  2. data/README.md +165 -0
  3. data/Rakefile +7 -0
  4. data/lib/nested_form/builder_mixin.rb +13 -1
  5. data/spec/dummy/app/assets/javascripts/jquery_events_test.js +19 -0
  6. data/spec/dummy/app/assets/javascripts/jquery_nested_form.js +42 -10
  7. data/spec/dummy/app/assets/javascripts/prototype_events_test.js +20 -0
  8. data/spec/dummy/app/assets/javascripts/prototype_nested_form.js +37 -32
  9. data/spec/dummy/app/models/project.rb +2 -0
  10. data/spec/dummy/app/models/project_task.rb +3 -0
  11. data/spec/dummy/app/views/layouts/application.html.erb +8 -0
  12. data/spec/dummy/app/views/projects/new.html.erb +0 -6
  13. data/spec/dummy/app/views/projects/without_intermediate_inputs.html.erb +11 -0
  14. data/spec/dummy/config/routes.rb +3 -1
  15. data/spec/dummy/db/development.sqlite3 +0 -0
  16. data/spec/dummy/db/migrate/20120819164528_add_association_with_class_name.rb +12 -0
  17. data/spec/dummy/db/schema.rb +6 -1
  18. data/spec/dummy/db/test.sqlite3 +0 -0
  19. data/spec/dummy/log/development.log +91 -0
  20. data/spec/dummy/log/test.log +710 -25
  21. data/spec/dummy/tmp/cache/assets/C99/4D0/sprockets%2F5e30a6b911437f1428dc32c3ae182123 +0 -0
  22. data/spec/dummy/tmp/cache/assets/C99/7D0/sprockets%2F79513e6956e0ee8624976e041fd5636d +0 -0
  23. data/spec/dummy/tmp/cache/assets/CAA/C90/sprockets%2F1e6c8ee1258009385ccf5b84015424b3 +0 -0
  24. data/spec/dummy/tmp/cache/assets/CB2/CB0/sprockets%2F11cc8d161d71a716dd36f16849d90870 +0 -0
  25. data/spec/dummy/tmp/cache/assets/CB7/7F0/sprockets%2Fac97b043470f6fcc925c352f16956643 +0 -0
  26. data/spec/dummy/tmp/cache/assets/CDB/8A0/sprockets%2Faed2a2575c376263c26e93b56b57051d +0 -0
  27. data/spec/dummy/tmp/cache/assets/D1F/A10/sprockets%2F60317e62cb324bfd9987e8da9636fd06 +0 -0
  28. data/spec/dummy/tmp/cache/assets/D49/870/sprockets%2F90896142645585acc8baf56ad57e3afb +0 -0
  29. data/spec/dummy/tmp/cache/assets/D62/F00/sprockets%2F6ac03a007f26b1c18ed3d53498ad3eb8 +0 -0
  30. data/spec/dummy/tmp/cache/assets/D79/BC0/sprockets%2F85a1db977361cc5130fcefb4637ff67e +0 -0
  31. data/spec/dummy/tmp/cache/assets/D87/1F0/sprockets%2F61c9ceafb877fb740c67416ff6f782a9 +0 -0
  32. data/spec/dummy/tmp/cache/assets/DAD/4F0/sprockets%2F765acd1bf68dc90f7d3e61da78b1e659 +0 -0
  33. data/spec/dummy/tmp/cache/assets/E03/3F0/sprockets%2F82b37ae9eccec44c1ef44cfdd07d8534 +0 -0
  34. data/spec/dummy/tmp/cache/assets/E0A/CA0/sprockets%2F7fe72ac1c0db1a7e8e7f59cf25e8a39e +0 -0
  35. data/spec/dummy/tmp/cache/assets/E3A/A60/sprockets%2F7c72c96cfc66454caf5fc8ca0fedd4f3 +0 -0
  36. data/spec/dummy/tmp/cache/assets/E54/400/sprockets%2Fd0cbc16cc37efcf9dc41f242b5dbbf81 +0 -0
  37. data/spec/dummy/tmp/cache/assets/EB7/AB0/sprockets%2F801d29a5debdbfbfb4eef14d70d9bcdb +0 -0
  38. data/spec/dummy/tmp/cache/assets/F48/5E0/sprockets%2F26cd6ffcffbebbe2fd6cd1a8f0c2debc +0 -0
  39. data/spec/dummy/tmp/capybara/capybara-201208212241496415482929.html +31 -0
  40. data/spec/events_spec.rb +60 -0
  41. data/spec/form_spec.rb +9 -0
  42. data/spec/nested_form/builder_spec.rb +67 -19
  43. data/vendor/assets/javascripts/jquery_nested_form.js +42 -10
  44. data/vendor/assets/javascripts/prototype_nested_form.js +37 -32
  45. metadata +102 -72
  46. data/README.rdoc +0 -101
@@ -1,101 +0,0 @@
1
- = Nested Form
2
-
3
- {<img src="https://secure.travis-ci.org/ryanb/nested_form.png?branch=master" alt="Build Status" />}[http://travis-ci.org/ryanb/nested_form]
4
-
5
- This is a Rails gem for conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery or Prototype.
6
-
7
- This gem only works with Rails 3. See the {rails2 branch}[https://github.com/ryanb/nested_form/tree/rails2] for a plugin to work in Rails 2.
8
-
9
- 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].
10
-
11
-
12
- == Setup
13
-
14
- Add it to your Gemfile then run +bundle+ to install it.
15
-
16
- gem "nested_form"
17
-
18
- And then add it to the Asset Pipeline in the appication.js file:
19
-
20
- //= require jquery_nested_form
21
-
22
-
23
- === Non Asset Pipeline Setup
24
-
25
- If you do not use the asset pipeline, run this generator to create the JavaScript file.
26
-
27
- rails g nested_form:install
28
-
29
- You can then include the generated JavaScript in your layout.
30
-
31
- <%= javascript_include_tag :defaults, "nested_form" %>
32
-
33
-
34
- == Usage
35
-
36
- Imagine you have a <tt>Project</tt> model that <tt>has_many :tasks</tt>. To be able to use this gem, you'll need to add <tt>accepts_nested_attributes_for :tasks</tt> to your Project model. If you wish to allow the nested objects to be destroyed, then add the <tt>:allow_destroy => true</tt> option to that declaration. If you don't have the <tt>accepts_nested_attributes_for :tasks</tt> you'll get a Missing Block Error. See the {accepts_nested_attributes_for documentation}[http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for] for details on all available options.
37
-
38
- This will create a <tt>tasks_attributes=</tt> method, so you may need to add it to the <tt>attr_accessible</tt> array. (<tt>attr_accessible :tasks_attributes</tt>)
39
-
40
- Then use the +nested_form_for+ helper method to enable the nesting.
41
-
42
- <%= nested_form_for @project do |f| %>
43
-
44
- You will then be able to use +link_to_add+ and +link_to_remove+ helper methods on the form builder in combination with fields_for to dynamically add/remove nested records.
45
-
46
- <%= f.fields_for :tasks do |task_form| %>
47
- <%= task_form.text_field :name %>
48
- <%= task_form.link_to_remove "Remove this task" %>
49
- <% end %>
50
- <p><%= f.link_to_add "Add a task", :tasks %></p>
51
-
52
-
53
- == SimpleForm and Formtastic Support
54
-
55
- Use <tt>simple_nested_form_for</tt> or <tt>semantic_nested_form_for</tt> for SimpleForm and Formtastic support respectively.
56
-
57
-
58
- == Partials
59
-
60
- 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.
61
-
62
- <%= f.fields_for :tasks %>
63
-
64
- In this case it will look for a partial called "task_fields" and pass the form builder as an +f+ variable to it.
65
-
66
-
67
- == Events
68
-
69
- If you are using jQuery, <tt>nested:fieldAdded</tt> and <tt>nested:fieldRemoved</tt> events are triggered on the +form+ element after adding and removing fields.
70
-
71
-
72
- == Enhanced jQuery JavaScript template
73
-
74
- You can override default behavior of inserting new subforms into your form. For example:
75
-
76
- window.nestedFormEvents.insertFields = function(content, assoc, link) {
77
- return $(link).closest('form').find(assoc + '_fields').append($(content));
78
- }
79
-
80
-
81
- == Project Status
82
-
83
- Unfortunately I have not had time to actively work on this project recently. If you find a critical issue where it does not work as documented please {ping me on Twitter}[http://twitter.com/rbates] and I'll take a look.
84
-
85
- == Contributing
86
-
87
- If you have any issues with Nested Form not addressed above or in the {example project}[http://github.com/ryanb/complex-form-examples/tree/nested_form], please add an {issue on GitHub}[http://github.com/ryanb/nested_form/issues] or {fork the project}[http://help.github.com/fork-a-repo] and send a {pull request}[http://help.github.com/send-pull-requests]. To run the specs:
88
-
89
- bundle install
90
- bundle exec rake spec:install
91
- bundle exec rake spec:all
92
-
93
- == Special Thanks
94
-
95
- 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].
96
-
97
- 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.
98
-
99
- 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.
100
-
101
- Thanks {Pavel Forkert}[https://github.com/fxposter] for the SimpleForm and Formtastic support.