Mellon
Mellon

Reputation: 38872

Use proc in Validation

In ruby on rails guide, there is a section 5.3 Using a Proc with :if and :unless discussed about Using a Proc with :if and :unless in validation helper. It gives the following example:

class Account < ActiveRecord::Base
  validates_confirmation_of :password,
    :unless => Proc.new { |a| a.password.blank? }
end

Does this 'a' in Proc refers to the current Account instance? Can I understand it(the 'a') as the reference of the current Account instance?

is the :password and a.password point at the same thing?

Upvotes: 4

Views: 1314

Answers (1)

Stephan
Stephan

Reputation: 2873

That is precisely what it is. a refers to the object being validated.

Upvotes: 9

Related Questions