Passing Values Between Action Methods

I have 2 action methods, action1 and action2. action1 is always run
before action2. Short of using the dreaded global variable, how can I
access a value developed in action1 from action2? Thanks for any
input.

       ... doug

If you are redirecting to action2 at the end of action1, just append
the value to the end of the redirect:

my_var = <some logic>
redirect_to :action => 'action2', :my_var => my_var

should work.

Peace,
Phillip

I have 2 action methods, action1 and action2. action1 is always run
before action2. Short of using the dreaded global variable, how can I
access a value developed in action1 from action2? Thanks for any
input.

u can send a value like this

def action1

redirect_to :action => ‘action2’, :value => params[:current_varaible]

end

def action2

puts params[:value].inspect

end

If you are redirecting to action2 at the end of action1, just append
the value to the end of the redirect:

Thanks to both responders. I appologize for not making clear that I'm
not redirecting from action1 to action2. Actually this is a checkout
system where action1 redirects to a checkout handler like PayPal and
then after the checkout handler does its thing, we redirect to a
fulfillment handler to complete the order. The bottom line is that
action1 does not "call" action2; so, I can't pass the information in
the call. That would obviously make life much easier.

Thanks for the input. Am I stuck with the dreaded global variable?

        ... doug

A global variable is probably not going to help you anyway.

If this "order" is in a database, then you may want to link this data that you need in action2 to the order as an attribute in the same table or in a new table the belongs_to :order (even if the need for the data is "temporary", you do need to handle concurrent users, right?).

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

(even if the need for
the data is "temporary", you do need to handle concurrent users,
right?).

Yep and I think that alone dictates what I'm going to have to do.
Thanks for helping me focus my thinking.

       ... doug