Forum: Ruby on Rails controller member variables

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C0f75c054e0191ad24dd655b2e1b4532?d=identicon&s=25 Reacher (Guest)
on 2007-07-05 21:33
(Received via mailing list)
I'm failing to see why a member variable in my controller won't keep
it's value.  Here's the setup:


  def index

  def mytoggle
    @show_loops = !@show_loops
    redirect_to :action => "index"


<% if @show_loops %>
  <% link_to "Hide Loops", { :action => "mytoggle" } %>
<% else %>
  <% link_to "Show Loops", { :action => "mytoggle" } %>
<% end %>
</h3><br />

When this HTML is rendered and  i click on "Hide Loops", the
@show_loops variable does get toggled from false to true, but when it
gets redirected back to index, the variable is back to false.  Am I
missing something obvious?
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-07-05 21:48
(Received via mailing list)
Rails controllers are not kept around. When a request comes in, a new
instance of the controller is made for that request only. Controller
instance variables are mainly used for flagging what data is to be
in the view. If you need data to persist across requests, you'll need to
it in the session.

C0f75c054e0191ad24dd655b2e1b4532?d=identicon&s=25 Reacher (Guest)
on 2007-07-05 22:02
(Received via mailing list)
got it.  thanks!
This topic is locked and can not be replied to.