How to preserve the value from the other action controller

Hi,

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]
end

def foo_two
puts @preserve_value
end

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

Yudi S.

On 19 March 2010 08:12, Yudi S. [email protected] wrote:

def foo_one
@my_value = params[:preserve_value]
end

def foo_two
puts @preserve_value
end

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

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).

Cheers,

Andy

Thanks for your reply.
I will do research on memcached

Yudi S.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs