Redirect to previous page after session timeout

Hi,
I would like to implement something like “go back to previous page is
session has expired” in my app.
If after 1 hour of inactivity the user performs an action, the app
should redirect user to login page, then when the user logs in, she/he
should be redirected to the previous page.

Is there a gem/plug-in or way to do this ?

ps:
I found how set activity limit in env file:

ActiveRecord::SessionStore::Session.recent_activity_limit = 1.hour
ActiveRecord::SessionStore::Session.auto_clean_sessions = 1

… but 2 things left: to perform a redirect after an hour to login page
and redirect to the previous page after user logs in.

If you have something in your application_controller.rb like:

before_filter :authenticate
def authenticate
if no_valid_session?
redirect_to :controller => ‘authentication’, :action => ‘login’
end
end

you could add there something like this:

session[:previous_uri] = request.request_uri

and then in ‘authentication#login’:

if session[:previous_uri] and session[:previous_uri] !=
request.request_uri
redirect_to session[:previous_uri]
else
redirect_to ‘/’
end

T.