on every page i have a button in the upper right that is either log in or log out. this button is pulled into my application.html.erb file by a partial ( _TopNav). I have tried a number of different ways to get this button to update when the session is destroyed, most simply. <% if session[:user_id]%> <%= my_logout_button %> <% else %> <%= my_login_button %> <% end %> the problem here is that i can''t get this part (the partial) to refresh. i am not to familiar with AJAX, but it seems like i could force this part of the page (the _TopNav) to refresh from my login or logout controller. any thoughts? best, tim -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
update the partial in your controller method which destroys the session: def logout session = nil render :update do |page| page.replace_html ''my_div'', :partial => ''topnav'' end end Mike On 3/14/08, Tim Booher <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > on every page i have a button in the upper right that is either log in > or log out. this button is pulled into my application.html.erb file by > a partial ( _TopNav). > > I have tried a number of different ways to get this button to update > when the session is destroyed, most simply. > > <% if session[:user_id]%> > <%= my_logout_button %> > <% else %> > <%= my_login_button %> > <% end %> > > the problem here is that i can''t get this part (the partial) to refresh. > i am not to familiar with AJAX, but it seems like i could force this > part of the page (the _TopNav) to refresh from my login or logout > controller. > > any thoughts? > > best, > > tim > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Garey wrote:> update the partial in your controller method which destroys the session: > > def logout > session = nil > > render :update do |page| > page.replace_html ''my_div'', :partial => ''topnav'' > end > end > > MikeMike, excellent, thanks for the help. i have to review the page object. best, tim -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am almost there, the problem is that topnav is a partial included in views\layouts\application.html.erb (i.e. layouts\_topnav). I have tried all sorts of ways to get the partial to look at layouts\_topnav.html.erb (things like :partial => ''\layouts\_topnav''). this might be working, but then i get a ''you have rendered twice'' error. any help greatly appreciated. best, tim Mike Garey wrote:> update the partial in your controller method which destroys the session: > > def logout > session = nil > > render :update do |page| > page.replace_html ''my_div'', :partial => ''topnav'' > end > end > > Mike-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
this is almost working: def logout session[:user_id] = nil render :update do |page| page.replace_html ''header'', :partial => ''/layouts/nav'' end flash[:notice] = "Logged out" redirect_to(:action => "login") end but i get an error: ActionController::DoubleRenderError in LoginController#logout Can only render or redirect once per action any thoughts on why this is? best tim Tim Booher wrote:> I am almost there, the problem is that topnav is a partial included in > views\layouts\application.html.erb (i.e. layouts\_topnav). I have tried > all sorts of ways to get the partial to look at layouts\_topnav.html.erb > (things like :partial => ''\layouts\_topnav''). this might be working, but > then i get a ''you have rendered twice'' error. > > any help greatly appreciated. > > best, > > tim > > Mike Garey wrote: >> update the partial in your controller method which destroys the session: >> >> def logout >> session = nil >> >> render :update do |page| >> page.replace_html ''my_div'', :partial => ''topnav'' >> end >> end >> >> Mike-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 15, 5:36 pm, Tim Booher <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> this is almost working: > > def logout > session[:user_id] = nil > render :update do |page| > page.replace_html ''header'', :partial => ''/layouts/nav'' > end > flash[:notice] = "Logged out" > redirect_to(:action => "login") > end > > but i get an error: > > ActionController::DoubleRenderError in LoginController#logout > > Can only render or redirect once per action > > any thoughts on why this is? >Well it''s exactly what it says, you can''t render something and redirect in the same action. Or to put things another way, if you redirect (ie send back a 302 response) the browser is just going to follow it, it doesn''t make sense to also render: the body of the http response is ignored. Even if you could it wouldn''t make any difference: you''re generating some javascript to change the page, but that page is being thrown away since the browser is being redirected to a new location. You shouldn''t need to be doing anything much beyond what you put in your first post, there''s probably something silly tripping you up. Messing around with ajax is almost certainly not what you need to do. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred, Great point and it''s well understood. My problem was that I was not adequately destroying the session, nor testing for the session''s existence correctly. I built the helper method logged_in? which works fine inside the partial. best, tim -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
also, you should probably place your topnav partial into views/shared. That''s where views that are to be shared between different actions should be stored. Topnav isn''t a layout, so it doesn''t really belong in the views/layouts dir. Mike On 3/15/08, Tim Booher <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Fred, > > Great point and it''s well understood. My problem was that I was not > adequately destroying the session, nor testing for the session''s > existence correctly. I built the helper method logged_in? which works > fine inside the partial. > > best, > > > tim > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How are you resetting your session? For example, session = nil as seen above doesn''t do much (it just creates a local variable called session and sets it to nil). If you want to clear out the whole session use reset_session. Just session[:foo]=nil will also work if you just want to clear that bit of it. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fred, great point. i am now using reset_session. regards, tim Frederick Cheung wrote:> How are you resetting your session? For example, > session = nil > as seen above doesn''t do much (it just creates a local variable called > session and sets it to nil). If you want to clear out the whole > session use reset_session. Just session[:foo]=nil will also work if > you just want to clear that bit of it. > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---