Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9392: ar_flaw_validates_presence_of_fixed.diff

File ar_flaw_validates_presence_of_fixed.diff, 1.2 kB (added by sur, 1 year ago)

patch fixing the flaw

  • activerecord/lib/active_record/validations.rb

    old new  
    490490 
    491491        # can't use validates_each here, because it cannot cope with nonexistent attributes, 
    492492        # while errors.add_on_empty can 
    493         attr_names.each do |attr_name| 
    494           send(validation_method(configuration[:on])) do |record| 
    495             unless (configuration[:if] && !evaluate_condition(configuration[:if], record)) || (configuration[:unless] && evaluate_condition(configuration[:unless], record)) 
    496               record.errors.add_on_blank(attr_name,configuration[:message]) 
    497             end 
    498           end 
    499         end 
     493        send(validation_method(configuration[:on])) do |record| 
     494          unless (configuration[:if] && !evaluate_condition(configuration[:if], record)) || (configuration[:unless] && evaluate_condition(configuration[:unless], record)) 
     495            record.errors.add_on_blank(attr_names, configuration[:message]) 
     496          end 
     497        end 
    500498      end 
    501499 
    502500      # Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time: