【问题标题】:Basic ActiveRecordStore updated_at field not being updated on every request基本 ActiveRecordStore updated_at 字段不会在每个请求上更新
【发布时间】:2009-04-02 19:35:43
【问题描述】:

我在我的应用程序中使用标准的 active_record_store。在environment.rb 我有:

config.action_controller.session_store = :active_record_store

我的sessions 表是用rake db:sessions:create 创建的:

create_table :sessions do |t|
  t.string :session_id, :null => false
  t.text :data
  t.timestamps
end

add_index :sessions, :session_id
add_index :sessions, :updated_at

但是,updated_at 列并未针对每个请求进行更新。它会在会话创建时更新(与created_at 的值相同,正如预期的那样),但不会针对任何后续请求。

奇怪的是,如果我在 environment.rb 中声明了以下显式调用,那么每次请求都会更新字段

class CGI::Session::ActiveRecordStore::Session
 def before_save
  self.updated_at = Time.now
 end
end

谁能解释为什么默认情况下这不起作用?

我正在运行 Rails 2.1.0——不,我目前无法升级 Rails! :)

【问题讨论】:

    标签: ruby-on-rails activerecord session


    【解决方案1】:

    您正在更新会话吗?如果您不更新值,那么我相信会话不会保存到磁盘。

    class WhateverController < ActionController
      def index
        session[:whatever] = true
      end
    end
    

    【讨论】:

    • 嗨弗朗索瓦。是的,我在每个请求上更新 session[:user],尽管值相同
    猜你喜欢
    • 2022-08-24
    • 1970-01-01
    • 2021-10-20
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多