This project is archived and is in readonly mode.
after_validate does not stop when false is returned
Reported by gucki | December 23rd, 2009 @ 06:56 AM
class Address < ActiveRecord::Base
acts_as_mappable
belongs_to :user belongs_to :country
validates_presence_of :address validates_length_of :address, :within => 3..100
validates_presence_of :country validates_associated :country
after_validation :geocode_address
private
def geocode_address
errors.add(:address, "Could not Geocode address")
return false
end end
Using "before_validation" instead of "after_validation" works.
Comments and changes to this ticket
-
Prem Sichanugrist (sikachu) December 25th, 2009 @ 04:01 PM
- Tag cleared.
I think this is an expected output.
You should have used
before_save
,before_create
orbefore_update
if you want to break the saving process of the record when something goes wrong.I think
after_validation
callback should only be used ifbefore_save
,before_create
orbefore_update
is not a suitable place to change the data that will fail the validation. -
Prem Sichanugrist (sikachu) January 20th, 2010 @ 12:48 PM
- State changed from new to wontfix
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>