Flowdock
method

on

Importance_2
Ruby on Rails latest stable (v4.0.2) - 1 note - Class: ActiveRecord::Errors

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

on(attribute) public

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
Show source
Register or log in to add new notes.
August 8, 2014 - (v3.0.0 - v4.0.2)
0 thanks

Deprecated in favour of []

In Rails 3+

company.errors[:name]

In Rails 2.3 and below:

company.errors.on(:name)