Ruby on Rails Thursday, April 29, 2010

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...@gmail.com> 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...@mac.com> 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@googlegroups.com.
> > > 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@googlegroups.com.
> > 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@googlegroups.com.
> 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@googlegroups.com.
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.

No comments:

Post a Comment