hii i have my ror app website want to do destroy session on browser close , please help how can i destroy.. i have used javascript function on body unload function bunload() { document.location.href="del.rb"; } </script> </head> <body onunload="bunload()"> and i have putted the del.rb file in my public folder and in that i have putted the following code session[:user] = nil but its not destroying the session.. please help.. thanks rahul -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Niels Meersschaert
2010-Apr-29 12:15 UTC
Re: want to destroy session on browser close for logout
Ruby files aren''t evaluated when they are in the Public folder, their contents are just returned to the user. You would need to have it call a controller action to run code. On Apr 29, 2010, at 8:01 AM, Rahul Mehta wrote:> hii > > i have my ror app website want to do destroy session on browser > close , > > please help how can i destroy.. > > i have used javascript function on body unload > > function bunload() > { > document.location.href="del.rb"; > } > </script> > </head> > <body onunload="bunload()"> > > and i have putted the del.rb file in my public folder and in that i > have putted the following code > > session[:user] = nil > > but its not destroying the session.. > > please help.. > > thanks > > rahul > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hiii thank for reply. can u help me how to run logout action of controller user on window.location.href.. thanks rahul On Thu, Apr 29, 2010 at 5:45 PM, Niels Meersschaert <nmeersschaert-ee4meeAH724@public.gmane.org>wrote:> Ruby files aren''t evaluated when they are in the Public folder, their > contents are just returned to the user. You would need to have it call a > controller action to run code. > > On Apr 29, 2010, at 8:01 AM, Rahul Mehta wrote: > > > hii > > > > i have my ror app website want to do destroy session on browser > > close , > > > > please help how can i destroy.. > > > > i have used javascript function on body unload > > > > function bunload() > > { > > document.location.href="del.rb"; > > } > > </script> > > </head> > > <body onunload="bunload()"> > > > > and i have putted the del.rb file in my public folder and in that i > > have putted the following code > > > > session[:user] = nil > > > > but its not destroying the session.. > > > > please help.. > > > > thanks > > > > rahul > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hiii niels thank for reply. can u help me how to run logout action of controller user on window.location.href.. thanks rahul On Apr 29, 5:15 pm, Niels Meersschaert <nmeersscha...-ee4meeAH724@public.gmane.org> wrote:> Ruby files aren''t evaluated when they are in the Public folder, their contents are just returned to the user. You would need to have it call a controller action to run code. > > On Apr 29, 2010, at 8:01 AM, Rahul Mehta wrote: > > > > > hii > > > i have my ror app website want to do destroy session on browser > > close , > > > please help how can i destroy.. > > > i have used javascript function on body unload > > > function bunload() > > { > > document.location.href="del.rb"; > > } > > </script> > > </head> > > <body onunload="bunload()"> > > > and i have putted the del.rb file in my public folder and in that i > > have putted the following code > > > session[:user] = nil > > > but its not destroying the session.. > > > please help.. > > > thanks > > > rahul > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Assuming you have a named_route for your logout action, you could try function bunload() { document.location.href="<%= logout_path %>"; } However, I would point out that unload isn''t guaranteed to be called & is even less likely to call & wait to load a new resource so that you can kill the session. Additionally, it''s usually a mark of spam sites (they do alert popups), so if at all possible you should avoid onunload. In reality, if you are using Rails defaults, the session is all stored on the client anyway, so there is no server load to have the session naturally expire when the browser quits (not when a user opens a different url or closes the window). If you are storing sessions on the server, you can easily setup a sweeper to clear out sessions not accessed in some time (or set that as a default in your environment) Niels instead of logout_path m giving string "/user/logout" which is the url for logout but its not working why. please help.. rahul m trying to call my user controller logout action from onunload function On Apr 29, 5:33 pm, Rahul Mehta <rahul23134...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hiii niels > > thank for reply. > > can u help me how to run logout action of controller user on > window.location.href.. > > thanks > > rahul > > On Apr 29, 5:15 pm, Niels Meersschaert <nmeersscha...-ee4meeAH724@public.gmane.org> wrote: > > > > > Ruby files aren''t evaluated when they are in the Public folder, their contents are just returned to the user. You would need to have it call a controller action to run code. > > > On Apr 29, 2010, at 8:01 AM, Rahul Mehta wrote: > > > > hii > > > > i have my ror app website want to do destroy session on browser > > > close , > > > > please help how can i destroy.. > > > > i have used javascript function on body unload > > > > function bunload() > > > { > > > document.location.href="del.rb"; > > > } > > > </script> > > > </head> > > > <body onunload="bunload()"> > > > > and i have putted the del.rb file in my public folder and in that i > > > have putted the following code > > > > session[:user] = nil > > > > but its not destroying the session.. > > > > please help.. > > > > thanks > > > > rahul > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.