Skip to content

Instantly share code, notes, and snippets.

@cheald
Created June 9, 2013 23:42
Show Gist options
  • Save cheald/5745739 to your computer and use it in GitHub Desktop.
Save cheald/5745739 to your computer and use it in GitHub Desktop.
c@luna /var/www/repos/test_before_save $ rails c
Loading development environment (Rails 3.2.13)
1.9.3p327 :001 > User.new.save
(0.0ms) begin transaction
(0.0ms) rollback transaction
RuntimeError: Kaboom!
from /var/www/repos/test_before_save/app/models/user.rb:6:in `bomb'
from /usr/local/rvm/gems/ruby-1.9.3-p327-perf/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:407:in `_run__4317644355368665104__save__697132430908302071__callbacks'
# ...
class User < ActiveRecord::Base
# attr_accessible :title, :body
before_save :bomb
def bomb
raise "Kaboom!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment