instance method
on
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
on(attribute)
Returns nil, if no errors are associated with the specified attribute. Returns the error message, if one error is associated with the specified attribute. Returns an array of error messages, if more than one error is associated with the specified attribute.
class Company < ActiveRecord::Base validates_presence_of :name, :address, :email validates_length_of :name, :in => 5..30 end company = Company.create(:address => '123 First St.') company.errors.on(:name) # => ["is too short (minimum is 5 characters)", "can't be blank"] company.errors.on(:email) # => "can't be blank" company.errors.on(:address) # => nil
Parameters
-
attributereq
Source
# File activerecord/lib/active_record/validations.rb, line 140
def on(attribute)
errors = @errors[attribute.to_s]
return nil if errors.nil?
errors.size == 1 ? errors.first : errors
end
Defined in activerecord/lib/active_record/validations.rb line 140
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Errors