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.

before_validation_on_create and before_validation_on_update doesn't exist

#4699

It seems that those two callbacks have been removed from the activerecords callbacks. Have they've been replaced some how? I've looked into the source code and couldn't figure it out.

Reported by hello (at convandesign) · May 26th, 2010 @ 05:39 AM

State: open
Milestone: 3.0.2
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. hello (at convandesign)
    hello (at convandesign)

    this is from the beta 3.0 branch....

    May 26th, 2010 @ 05:40 AM

  2. ddelco
    ddelco

    Any answers on this? activerecord/lib/active_record/callbacks.rb still references _on_create and _on_update validations in the documentation, but they don't seem to be there anymore.

    June 6th, 2010 @ 01:37 AM

  3. Neeraj Singh
    Neeraj Singh

    before_validation_on_create and before_validation_on_update methods are available. The syntax has changed.

      before_validation(:on => :create){ do_something }
      before_validation(:on => :update){ do_something }
    

    Yes the documentation needs to be updated.

    June 7th, 2010 @ 09:56 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.
    • Tag set to activerecord, callbacks, documentation
    • State changed from new to resolved
    • Assigned user set to Santiago Pastorino

    June 8th, 2010 @ 02:35 AM

  5. David Williams
    David Williams

    It's not completely resolved. The paragraph directly above the committed change also needs work. It currently says:

    "That’s a total of ten callbacks, which gives you immense power to react and prepare for each state in the Active Record lifecycle. The sequence for calling Base#save for an existing record is similar, except that each on_create callback is replaced by the corresponding on_update callback."

    Except that this is the first mention of on_create and on_update, and they don't actually exist anymore. More information would be useful. For instance, is it possible to use the ":on" option and also pass a symbol, or is the block form the only one supported?

    June 16th, 2010 @ 02:42 AM

  6. Neeraj Singh
    Neeraj Singh
    • Tag cleared.

    Anyone can make changes to http://github.com/lifo/docrails . So please go ahead and make the necessary changes to the documentation.

    June 16th, 2010 @ 05:03 AM

  7. Neeraj Singh
    Neeraj Singh

    Did not mean to clear tag. Not sure why tag got cleared.

    June 16th, 2010 @ 06:11 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM

  9. Matt Buck
    Matt Buck
    • Tag set to documentation

    Looks like David's comment above was resolved by https://github.com/lifo/docrails/commit/5a6f651a6a093f69f00fa713648...

    I'm looking at clarifying this documentation a bit, but I'm confused by the new callback system. The documentation still refers to overriding methods like before_destroy, but the examples look like these methods are now meant to be invoked rather than overridden. If somebody can point me in the right direction, I'll commit a fix.

    February 8th, 2011 @ 07:49 PM

  10. bingbing
  11. Greg Hazel
    Greg Hazel
    • State changed from resolved to open

    I also could use some clarification on the documentation. Is this form allowed?

    before_validation :do_something, :on => :create
    

    [state:open]

    As a side note, it would make upgrading from Rails 2 to Rails 3 easier if this were more clearly documented or simply backwards compatible with Rails 2 applications using before_validation_on_create etc.

    March 31st, 2011 @ 01:10 AM