This project is archived and is in readonly mode.

#775 ✓invalid
Tom Lea

Per-Instance Callbacks

Reported by Tom Lea | August 7th, 2008 @ 06:13 PM | in 2.x

This patch allows callbacks to be hooked up on an individual instance.


class SomeStorage
  include ActiveSupport::Callbacks
  define_callbacks :before_save, :after_save
  def save
    run_callbacks(:before_save)
    puts "- save"
    run_callbacks(:after_save)
  end
end

store = SomeStorage.new

store.before_save do |object|
  puts "saving..."
end

store.after_save do |object|
  puts "saved."
end

store.save

#
# Output:
#   saving...
#   - save
#   saved

Comments and changes to this ticket

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>

People watching this ticket

Attachments

Pages