Passing arguments to transitions

481 views
Skip to first unread message

Johan Bruning

unread,
Jan 4, 2012, 8:20:01 AM1/4/12
to PluginAWeek: Talk
I've just started using state_machine gem and it has already cleaned
up a lot of my code. I do however need to do 1 specific thing and
can't figure out from the README if/how this can be done.

All the code will be used in a Rails 3 app.

Let's say I have an article model which looks something like this:

state_machine :state, :initial => :new do
event :submit_for_approval do
transition [:new, :declined] => :pending
end

event :decline do
transition [:pending] => :declined
end

event :approve do
transition [:pending, :declined] => :published
end
end

This will give me the following methods (among others):

submit_for_approval, approve and decline.

Let's say I would like to keep a log of whoever performed these
actions on the given article.
I know there is something called state_machine-audit_trail, however
this only logs the changes.
I would like to pass in the invoker of the change in the
submit_for_approval, approve and decline methods. How can I achieve
this ?

If this is not possible or considered a bad practice what would you
suggest ?

Aaron Pfeifer

unread,
Jan 8, 2012, 3:41:07 PM1/8/12
to pluginaw...@googlegroups.com
Hi Johan,

See the section titled "Defining additional arguments" at http://rubydoc.info/github/pluginaweek/state_machine/master/StateMachine/Machine:event

Best,
Aaron


--
You received this message because you are subscribed to the Google Groups "PluginAWeek: Talk" group.
To post to this group, send email to pluginaw...@googlegroups.com.
To unsubscribe from this group, send email to pluginaweek-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pluginaweek-talk?hl=en.


Reply all
Reply to author
Forward
0 new messages