Platinum Partner

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
{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}