Skip to content

Instantly share code, notes, and snippets.

@ka8725
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka8725/9767340 to your computer and use it in GitHub Desktop.
Save ka8725/9767340 to your computer and use it in GitHub Desktop.
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