Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for active record callbacks #182

Closed
dhwanitgupta opened this issue Jun 17, 2016 · 2 comments
Closed

support for active record callbacks #182

dhwanitgupta opened this issue Jun 17, 2016 · 2 comments

Comments

@dhwanitgupta
Copy link

Hi

Problem: To log changes in any model I am using after_commit callback if active record, but when I change state using event then I am not able to use after_commit callback. Is there any way to handle this ?

Basically I want to log any change in model, as after_commit only runs after transaction block is successfully executed therefore I am using after_commit callback

Any help ?

@asanger
Copy link

asanger commented Jun 23, 2016

What I had to do was add the following to my Workflow model:

workflow do

  ...

  on_transition do |from, to, event, *event_args|
    self.update_attribute(:status, to)
  end
end

It's a bit of a hack, but it ensures that the callbacks get triggered on every state transition. Been using it for quite a while now and haven't had any issues with it. Make sure that :status is the name of your state attribute.

@kartikv11
Copy link

@geekq This issue can be closed, as the solution provided by @asanger is perfect.

@geekq geekq closed this as completed May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants