Hobo 1.3: Accessing record values before and after the transition change in its do block

22 views
Skip to first unread message

Ronny Hanssen

unread,
Jul 12, 2012, 5:58:30 PM7/12/12
to hobo...@googlegroups.com
Hi,

I have defined a transition with :param for a couple of fields that the user may change when the transition is invoked. So far so good. I then added a do block for the transition in order for me to send an email about the changes.

The problem is that I want to indicate in the mail what has changed (old value and new value). Is there some way I can access the record values as they where before the transition was run?

Regards,
Ronny

Ronny Hanssen

unread,
Jul 12, 2012, 6:52:52 PM7/12/12
to hobo...@googlegroups.com
Forget it. I just found that self in the do block contains @previously_changed, which holds anything I need. Hobo is (as usual) way ahead of me :)

Regards,
Ronny

Matt Jones

unread,
Jul 12, 2012, 7:11:56 PM7/12/12
to hobo...@googlegroups.com

On Jul 12, 2012, at 6:52 PM, Ronny Hanssen wrote:

> Forget it. I just found that self in the do block contains @previously_changed, which holds anything I need. Hobo is (as usual) way ahead of me :)
>
> Regards,
> Ronny

Did some quick digging (as I'd never heard of that) and it's actually not a Hobo thing - it's part of ActiveModel! It's probably better to call previous_changes instead, since accessing mysterious instance variables is tricky, but that accomplishes the same thing:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/dirty.rb#L127

--Matt Jones

Ronny Hanssen

unread,
Jul 12, 2012, 9:47:02 PM7/12/12
to hobo...@googlegroups.com
Ah. I see. I actually thought this was a Hobo thing :). Yeah, you are right about that. Should use previous_changes instead, a very small change in my code but better to use the api methods. Thanks for the digging :)

~Ronny
Reply all
Reply to author
Forward
0 new messages