how to preserve the value from the other action controller


Anyone knows how to preserve the value from the previous action controller?

For example,

  • I have 2 controllers: foo_one and foo_two.
  • on action foo_one, I have variable @my_value
  • How I can keep the value of @my_value so I can use it on the second controller foo_two

def foo_one
@my_value = params[:preserve_value]

def foo_two
puts @preserve_value

I don’t want to use session or global variable. any suggestion?

Yudi Soesanto

Assuming foo_one calls foo_too (so it’s in the same request - hence your global variable mention), then you could define an attr_accessor on foo_two’s controller and set it from there.

But, if it’s not being executed in the same request, session (be it Rails session, database or memcached) is the only way (or flash so it’s automatically removed after the next request).



Thanks for your reply.

I will do research on memcached

Yudi Soesanto