Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

after_validate does not stop when false is returned

#3607

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.

Reported by gucki · December 23rd, 2009 @ 06:56 AM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • Tag cleared.

    I think this is an expected output.

    You should have used before_save, before_create or before_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 if before_save, before_create or before_update is not a suitable place to change the data that will fail the validation.

    December 25th, 2009 @ 04:01 PM

  2. Prem Sichanugrist (sikachu)