我有一个模型word-wrap:break-word
,我有一个设计模型profile
。目前,我在我的设备会话控制器中有一个自定义方法,通过会话检查profile_id:
user
这里的问题是我最近才注意到我必须在会话数据库上做一些内务管理。我最近在我的开发环境中运行 after_action :assign_profile, only: [:create]
def assign_profile
if session[:profile_id]
@tutor.profile = Profile.find(session[:profile_id]) if @tutor.persisted?
session.delete(:profile_id)
end
end
,因为我想测试一个" fresh"现场。
现在使用全新rake db:reset
登录时,我遇到此错误:user
。显然,这意味着我的会话数据库尚未被删除。我还尝试清除浏览器的缓存并重新启动我的rails服务器(我实际上使用了隐身模式,因此不应该成为问题),但这也不起作用。
我做了一些简单的谷歌搜索和正确的任务,据说是Couldn't find Profile with 'id'=4
。但是,这给了我这个错误:rake db:sessions:clear
。
所以现在,我被困住了。我无法测试我的网站,我无法弄清楚如何清理我的开发会话数据库并从头开始。 (我正在运行Rails 5.1)
更新: 我尝试过包含以下rake任务(将来作为cron作业运行)
Don't know how to build task 'db:sessions:clear' (see --tasks)
我收到了这个错误:
desc "Clear expired sessions"
task :clear_expired_sessions => :environment do
sql = "DELETE FROM sessions WHERE updated_at < (CURRENT_TIMESTAMP - INTERVAL '1 days');"
ActiveRecord::Base.connection.execute(sql)
end
现在我更加困惑。我的会话在哪里存储呢?在能够以这种方式处理会话之前我应该包括this active record session store gem吗?
更新2: 重新启动计算机已清除已持久的会话数据。如果有人能够解决我所面临的问题,我仍然会非常感激。
答案 0 :(得分:2)
更改Rails密钥将使所有cookie无效。
要清除计算机重启后实际发生的所有临时存储,请运行rails tmp:clear
任务 - 请参阅tmp
description here。
或者您可以创建用于清除缓存存储的自定义任务:
# lib/tasks/sessions.rake:
namespace :sessions do
desc "Clear Rails.sessions"
task :clear do
ActiveSupport::Cache.lookup_store(Rails.configuration.cache_store).clear
puts "Successfully cleared Rails.sessions!"
end
end
然后运行:
$ bundle exec rake sessions:clear