Coder Social home page Coder Social logo

after-commit-on-action's Introduction

After Commit on Action

Move your after_commit callbacks to your Rails Observers.

If you are defining an after_commit block in your Rails model directly, you have the option to specify when (on create, update, destroy) that block should be run.

Example:

class Foo
  after_commit :on => :create do
    send_create_email
  end

  after_commit :on => :update do
    send_update_email
  end
  
  after_commit :on => :destroy do
    send_destroy_email
  end
end

If you wanted to move this code to your observers, you will find that you cannot specify the on option. To remedy that limitation, this gem allows you to create the following callbacks in your Rails Observers:

  • after_commit_on_create
  • after_commit_on_update
  • after_commit_on_save
  • after_commit_on_destroy

Example:

class Foo
end

class FooObserver < ActiveRecord::Observer
  observe :foo

  def after_commit_on_create(foo)
    send_create_email
  end

  def after_commit_on_update(foo)
    send_update_email
  end

  def after_commit_on_save(foo)
    send_save_email
  end

  def after_commit_on_destroy(foo)
    send_destroy_email
  end

after-commit-on-action's People

Contributors

yunussasmaz avatar

Stargazers

augus avatar

Watchers

James Cloos avatar  avatar

after-commit-on-action's Issues

Are you still maintaining this?

I love the idea for this project, and I was thinking about using it for something. Do you still maintain it at all? I'll let you know if I can get it working with Rails 4.

Thanks! ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.