Permalink
Browse files

jotting down thoughts

  • Loading branch information...
0 parents commit ee800593c3b91aaf50abe34cda36224d4501dde4 @cainlevy committed Dec 11, 2008
Showing with 75 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +19 −0 README
  3. +23 −0 Rakefile
  4. +1 −0 init.rb
  5. +1 −0 lib/nested_assignment.rb
  6. +8 −0 test/nested_assignment_test.rb
  7. +3 −0 test/test_helper.rb
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Lance Ivy
+
+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.
19 README
@@ -0,0 +1,19 @@
+NestedAssignment
+================
+
+An attempt at solving the model (and controller) side of nested forms. Based on thoughts pulled from http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4049b4b313fa8be2, http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5/f0a19fc01d0246fc, and work on ActiveScaffold.
+
+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.
+
+and of course:
+
+# Skinny controllers. There's no footprint in the controller, actually.
+
+Copyright (c) 2008 Lance Ivy, released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the nested_assignment plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the nested_assignment plugin.'
+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('lib/**/*.rb')
+end
1 init.rb
@@ -0,0 +1 @@
+# Include hook code here
1 lib/nested_assignment.rb
@@ -0,0 +1 @@
+# NestedAssignment
8 test/nested_assignment_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class NestedAssignmentTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
3 test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'

0 comments on commit ee80059

Please sign in to comment.