I''m failing to see why a member variable in my controller won''t keep it''s value. Here''s the setup: editor_controller.rb: ... def index display_loops end def mytoggle @show_loops = !@show_loops redirect_to :action => "index" end ... index.rhtml: <h3> <% 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 available in the view. If you need data to persist across requests, you''ll need to put it in the session. Jason On 7/5/07, Reacher <brandon.g.jones-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m failing to see why a member variable in my controller won''t keep > it''s value. Here''s the setup: > > editor_controller.rb: > > ... > def index > display_loops > end > > def mytoggle > @show_loops = !@show_loops > redirect_to :action => "index" > end > ... > > index.rhtml: > > <h3> > <% 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? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
got it. thanks! On Jul 5, 3:47 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 available > in the view. If you need data to persist across requests, you''ll need to put > it in the session. > > Jason > > On 7/5/07, Reacher <brandon.g.jo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m failing to see why a member variable in my controller won''t keep > > it''s value. Here''s the setup: > > > editor_controller.rb: > > > ... > > def index > > display_loops > > end > > > def mytoggle > > @show_loops = !@show_loops > > redirect_to :action => "index" > > end > > ... > > > index.rhtml: > > > <h3> > > <% 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---