Thursday, 8 November 2012

Validation is very useful in rails

http://guides.rubyonrails.org/active_record_validations_callbacks.html#validates_with

5.3 Using a Proc with :if and :unless

Finally, it’s possible to associate :if and :unless with a Proc object which will be called. Using aProc object gives you the ability to write an inline condition instead of a separate method. This option is best suited for one-liners.
class Account < ActiveRecord::Base
  validates :password, :confirmation => true,
    :unless => Proc.new { |a| a.password.blank? }
end

0 comments:

Post a Comment