Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails Validations not running when I use :on => :save option
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