activerecord-session_storeでセッション管理をしています。
セッションクリーニングで30分以上、操作がないユーザーのセッションを削除しようと思っています。
ですが、sessionsテーブルのupdated_atの更新は画面遷移(index/showなど)では更新されませんでした。
常時、更新するためにapplication_controller.rbで以下の処理を入れてみたのですが
あまり賢い方法とは思えません。
他にいい方法はないでしょうか?
ruby
1diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb 2index e6f71ad..ff1a3a1 100644 3--- a/app/controllers/application_controller.rb 4+++ b/app/controllers/application_controller.rb 5@@ -8,6 +8,8 @@ class ApplicationController < ActionController::Base 6 7 helper_method :current_user 8 9+ before_action :last_operated_at 10+ 11 protected 12 def current_user 13 @current_user ||= User.find_by(id: session[:current_user_id]) 14@@ -28,4 +30,8 @@ class ApplicationController < ActionController::Base 15 end 16 end 17 end 18+ 19+ def last_operated_at 20+ session[:last_operated_at] = DateTime.now 21+ end 22 end 23
環境:
Ruby 2.3.1
Ruby on Rails 4.2
あなたの回答
tips
プレビュー