【问题标题】:Ruby 2.3.5 ActiveRecord::RecordNotFound cannot figure out how to deleteRuby 2.3.5 ActiveRecord::RecordNotFound 无法弄清楚如何删除
【发布时间】:2018-08-11 07:50:51
【问题描述】:

我以为我重置了我的数据库,但我似乎有剩余用户:

找不到 'id'=4 的用户

app/controllers/application_controller.rb:7:in `current_user'

app/views/layouts/_top_nav.html.erb:29:in `_app_views_layouts__top_nav_html_erb__3420316131555447158_70352716890940'

app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1486453009680454139_40255060'

def current_user
  @current_user ||= User.find(session[:user_id]) if session[:user_id]
end

helper_method :current_user

我使用了 bin/rake db:reset,但是当我连接到服务器时仍然得到以下信息:

D, [2018-03-03T03:12:09.426337 #11896] DEBUG -- : 用户负载 (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 4]]

如何删除用户(我怀疑用户 1、2、3 也需要删除)

【问题讨论】:

    标签: ruby database rake reset


    【解决方案1】:

    问题是cookies是客户端的。你使用的是什么浏览器?尝试清除浏览器上的cookies


    也许您可以通过使用debugger 在您的操作:current_user 中使用session.clear

    【讨论】:

    • 我正在使用 Chrome。我清空了缓存并重新加载了
    • cookies,而不是caches。您确定您已删除 localhost:3000 上的 cookie 吗?
    • 好的,我的控制器中似乎没有会话杀手。它到底应该去哪里。新手问题,但我只使用 Ruby 4 天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    相关资源
    最近更新 更多