Skip to content

Instantly share code, notes, and snippets.

@rwz
Created December 13, 2010 06:50
Show Gist options
  • Save rwz/738734 to your computer and use it in GitHub Desktop.
Save rwz/738734 to your computer and use it in GitHub Desktop.
state_machine + delayed_job wtf
# doesn't fucking work
class Logo < ActiveRecord::Base
state_machine :state, :initial => :initial do
# here vvv
after_transition :initial => :used, :do => :test_callback
# here ^^^
event :use do
transition :initial => :used
end
end
def test_callback
raise 'Fuck'
end
handle_asynchronously :test_callback
end
# works
class Logo < ActiveRecord::Base
state_machine :state, :initial => :initial do
# here vvv
after_transition :initial => :used do |logo, t|
logo.test_callback
end
# here ^^^
event :use do
transition :initial => :used
end
end
def test_callback
raise 'Fuck'
end
handle_asynchronously :test_callback
end
@ambethia
Copy link

ambethia commented Aug 1, 2011

Found this in google, I know it's old, but if you never figured it out: I assume handle_asynchronously is hooking your callback method in a way that the original method is still being called when you use the :do => :callback syntax in the state machine. In the block you are calling it directly, allowing whatever aliasing is going on behind the scenes in DelayedJob to work.

@sergio-fry
Copy link

thank you!!!! fucking fuck! :)

@amw
Copy link

amw commented Sep 1, 2012

Thank you.

@endzyme
Copy link

endzyme commented Aug 30, 2013

you rock

@mikepollitt
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment