Created
April 17, 2013 13:26
-
-
Save aditya-kapoor/5404279 to your computer and use it in GitHub Desktop.
Rails Validations not running when I use :on => :save option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist is in reference to the documentation for the Rails 3.2.13 on Ruby 1.9.3 p194 (http://guides.rubyonrails.org/active_record_validations_callbacks.html#on) where it has highlighted the fact that the validations for presence can also be run using the :on => :save option. The following code will highlight it better | |
class User < ActiveRecord::Base | |
attr_accessible :name | |
validates :name, :presence => true, :on => :save | |
end | |
u = User.create | |
u.errors #=> nil | |
u = User.first | |
u.name = "" | |
u.save #=> nil | |
The presence validation for name has not fired which is contradictory to what is stated in the above guide. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment