Last active
August 29, 2015 13:57
-
-
Save ka8725/9767340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db.sqlite3') | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
end | |
end | |
class ActiveRecord::Base | |
cattr_accessor :skip_callbacks | |
end | |
class User < ActiveRecord::Base | |
after_create :send_greeting_email, unless: :skip_callbacks | |
private | |
def send_greeting_email | |
puts 'Sending greeting email..' | |
end | |
end | |
ActiveRecord::Base.skip_callbacks = true | |
User.create | |
# => Sending greeting email.. | |
ActiveRecord::Base.skip_callbacks = false | |
User.create | |
# Will output nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment