Over a million developers have joined DZone.

Rails Session Timeout

·
Adicionando Timeout na sessão do Rails.

Em application_controller.rb:

before_filter :session_expiry, :except => [:login, :logout]
before_filter :update_activity_time, :except => [:login, :logout]

def session_expiry
  @time_left = (session[:expires_at] - Time.now).to_i
  unless @time_left > 0
    reset_session
    flash[:error] = 'Sua sessão expirou. Favor entrar novamente.'
    redirect_to :controller => 'login', :action => 'login'
  end
end

def update_activity_time
  session[:expires_at] = 60.minutes.from_now
end


Em login_controller.rb:

update_activity_time
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}