Do not use ActiveRecord::Base.new(hsh) when instantiating AR models. Use form of instantiation that allows protected attributes to be set.

master
Zach Dennis 2011-04-29 00:13:26 -04:00
parent 71184b2903
commit 5aefbb2989
1 changed files with 3 additions and 1 deletions

View File

@ -245,7 +245,9 @@ class ActiveRecord::Base
# keep track of the instance and the position it is currently at. if this fails
# validation we'll use the index to remove it from the array_of_attributes
arr.each_with_index do |hsh,i|
instance = new( hsh )
instance = new do |model|
hsh.each_pair{ |k,v| model.send("#{k}=", v) }
end
if not instance.valid?
array_of_attributes[ i ] = nil
failed_instances << instance