want to destroy session on browser close for logout

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

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.

hiii

thank for reply.

can u help me how to run logout action of controller user on window.location.href…

thanks

rahul

hiii niels

thank for reply.

can u help me how to run logout action of controller user on
window.location.href..

thanks

rahul

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