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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}