Skip to content
Browse files

rdoc

  • Loading branch information...
1 parent 1d2d8dc commit 41f7a39d87bb6525b63c79ec1212a61310b13724 @cainlevy committed Dec 12, 2008
Showing with 23 additions and 16 deletions.
  1. +22 −15 README.rdoc
  2. +1 −1 Rakefile
View
37 README.rdoc
@@ -4,25 +4,32 @@ An attempt at solving the model (and controller) side of nested forms. Based on
== Goals:
-# Assigning attributes should remain in-memory. Nothing should be permanent before #save. This means avoiding some of ActiveRecord's association assignment logic such as AssociationCollection#replace.
-# Deep and thorough validation of all new and changed associated records. In order for all possible errors to be available at once, no single invalid record may halt the process.
-# Support HTML-only forms. This means using a :_delete param to delete records, since that can be accomplished with a checkbox and does not require JavaScript to remove input fields from the form data. Credit to Josh Susser.
-# Use parameter hashes for collections instead of arrays, because params order can't be guaranteed through AJAX (credit to James Golick) and Rails' parameter parser has troubles with arrays of complex objects (e.g. params[:user][:photos][][:title]). The hash key should not be meaningful (such as the record id) or magical (such as new_1234), so that it may be generated by any means. Using a timestamp is particularly effective, since it also provides a maintainable order (credit to Eloy Duran).
-# Nested mass assignment should be enabled manually for security and performance reasons.
-# Nested mass assignment params should be keyed with a suffix (e.g. _params) to avoid complicating association assignment logic. This means params[:user][:photos_params] instead of params[:user][:photos], which assigns via User#photo_params= instead of User#photos=. The former can be tailored to the specific needs of form input, whereas the latter is best for in-memory association management. This constraint could conceivably be removed later, once mass assignment is more mature.
+1. Assigning attributes should remain in-memory. Nothing should be permanent before #save. This means avoiding some of ActiveRecord's association assignment logic such as AssociationCollection#replace.
+2. Deep and thorough validation of all new and changed associated records. In order for all possible errors to be available at once, no single invalid record may halt the process.
+3. Support HTML-only forms. This means using a :_delete param to delete records, since that can be accomplished with a checkbox and does not require JavaScript to remove input fields from the form data. Credit to Josh Susser.
+4. Use parameter hashes for collections instead of arrays, because params order can't be guaranteed through AJAX (credit to James Golick) and Rails' parameter parser has troubles with arrays of complex objects (e.g. params[:user][:photos][][:title]). The hash key should not be meaningful (such as the record id) or magical (such as new_1234), so that it may be generated by any means. Using a timestamp is particularly effective, since it also provides a maintainable order (credit to Eloy Duran).
+5. Nested mass assignment should be enabled manually for security and performance reasons.
+6. Nested mass assignment params should be keyed with a suffix (e.g. _params) to avoid complicating association assignment logic. This means params[:user][:photos_params] instead of params[:user][:photos], which assigns via User#photo_params= instead of User#photos=. The former can be tailored to the specific needs of form input, whereas the latter is best for in-memory association management. This constraint could conceivably be removed later, once mass assignment is more mature.
+7. Skinny controllers. There's no footprint in the controller, actually. This is mass assignment.
-and of course:
-
-# Skinny controllers. There's no footprint in the controller, actually.
-
-== Paradigm Params (cf http://gist.github.com/10793)
+== Paradigm Params (see http://gist.github.com/10793)
{
- :task_params =>
+ # singular associations
+ :avatar_params => {
+ :id => '7',
+ :name => 'mugshot.jpg'
+ },
+
+ # plural associations
+ :tasks_params =>
{
- '1' => { :id => '3', :name => "Foo" },
- '2' => { :id => '5', :name => "Bar", :_delete => true}
- '3' => { :name => "Baz" }
+ # create
+ '1' => { :name => "Baz" },
+ # update
+ '2' => { :id => '3', :name => "Foo" },
+ # destroy
+ '3' => { :id => '5', :name => "Bar", :_delete => true}
}
}
View
2 Rakefile
@@ -18,6 +18,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'NestedAssignment'
rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

0 comments on commit 41f7a39

Please sign in to comment.
Something went wrong with that request. Please try again.