diff options
Diffstat (limited to 'activerecord/lib/active_record/validations.rb')
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index cc372b5042..c9d4740670 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -333,7 +333,8 @@ module ActiveRecord attr_accessor *(attr_names.map { |n| "#{n}_confirmation" }) validates_each(attr_names, configuration) do |record, attr_name, value| - record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation") + confirm = record.send("#{attr_name}_confirmation") + record.errors.add(attr_name, configuration[:message]) unless value.nil? || value == confirm end end @@ -374,6 +375,10 @@ module ActiveRecord # # The first_name attribute must be in the object and it cannot be blank. # + # If you want to validate the presence of a boolean field (where the real values are true and false), + # you will want to use validates_inclusion_of :field_name, :in => [true, false] + # This is due to the way Object#blank? handles boolean values. false.blank? # => true + # # Configuration options: # * <tt>message</tt> - A custom error message (default is: "can't be blank") # * <tt>on</tt> - Specifies when this validation is active (default is :save, other options :create, :update) @@ -538,7 +543,7 @@ module ActiveRecord condition_params << scope_value end end - unless record.new? + unless record.new_record? condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" condition_params << record.send(:id) end @@ -772,7 +777,7 @@ module ActiveRecord run_validations(:validate) validate - if new? + if new_record? run_validations(:validate_on_create) validate_on_create else |