Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
jotting down thoughts
Browse files Browse the repository at this point in the history
  • Loading branch information
cainlevy committed Dec 11, 2008
0 parents commit ee80059
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Include hook code here
1 change: 1 addition & 0 deletions lib/nested_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# NestedAssignment
8 changes: 8 additions & 0 deletions test/nested_assignment_test.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'

0 comments on commit ee80059

Please sign in to comment.