在生产模式中无意中破坏了Rails Devise会话

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在生产模式中无意中破坏了Rails Devise会话相关的知识,希望对你有一定的参考价值。

在生产模式下成功登录我的Rails应用程序后,我将尝试单击表顶部的过滤器按钮之一:“所有服务器”,“进行中”或“修复”。 按下其中一个按钮后,会话将被破坏,并将用户重定向回登录页面; 但是,这在开发环境中不会发生 。 在开发环境中,当用户按下过滤器按钮之一时,将应用适当的范围,并且不会发生重定向。

在将生产日志与开发日志进行比较之后,该错误似乎出现在Devise::SessionsController#new

可以在以下位置找到源代码: https//github.com/herman5/warthog

我将应用程序托管在Heroku上,因此可以看到效果。

网址http//testdomain.dcmdashboard.com

电子邮件 :moderator@example.com

密码 :密码

登录并在开发环境中按下过滤器按钮( GET "/?order=id_desc&page=1&scope=in_progress" )后:

Started POST "/users/sign_in" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Processing by Devise::SessionsController#create as html
  Parameters: "utf8"=>"✓", "authenticity_token"=>"UmLj+rzYzRWPr/Y7G5q2Y+/6KptI6X1EzoE7xJCjCIQ=", "user"=>"email"=>"moderator@example.com", "password"=>"[FILTERED]", "remember_me"=>"0", "commit"=>"Sign in"
  Tenant Load (1.4ms)  SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
  User Load (1.7ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'moderator@example.com' LIMIT 1
   (1.6ms)  BEGIN
   (2.5ms)  UPDATE "users" SET "last_sign_in_at" = '2013-12-30 00:14:55.058879', "current_sign_in_at" = '2013-12-30 01:40:15.445913', "sign_in_count" = 3, "updated_at" = '2013-12-30 01:40:15.450781' WHERE "users"."id" = 3
   (1.6ms)  COMMIT
Redirected to http://testdomain.warthog.dev/admin
Completed 302 Found in 131ms (ActiveRecord: 1.0ms)


Started GET "/admin" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Processing by Admin::ServersController#index as HTML
  Tenant Load (1.7ms)  SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
  User Load (32.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
   (2.8ms)  SELECT COUNT(*) FROM "servers" WHERE ('t')
   (2.5ms)  SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
   (4.0ms)  SELECT COUNT(*) FROM "servers" WHERE (build_stage = '7 - Build Team Remediation' OR build_stage = '13 - SecOps Remediation')
   (2.4ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
  CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
   (2.6ms)  SELECT COUNT(*) FROM "servers"
  CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
  Server Load (2.6ms)  SELECT "servers".* FROM "servers" ORDER BY "servers"."id" desc LIMIT 30 OFFSET 0
  Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (354.6ms)
Completed 200 OK in 403ms (Views: 342.4ms | ActiveRecord: 54.0ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/lib/namespace.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery_ujs.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /active_admin/components/jquery.aa.checkbox-toggler.js - 304 Not Modified (0ms)
Served asset /active_admin/lib/namespace.js - 304 Not Modified (0ms)



Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600

Started GET "/assets/active_admin/components/jquery.aa.dropdown-menu.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery-ui.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.table-checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.dropdown-menu.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.popover.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.table-checkbox-toggler.js - 304 Not Modified (4ms)


Started GET "/assets/active_admin/pages/batch_actions.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.popover.js - 304 Not Modified (5ms)


Started GET "/assets/active_admin/pages/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/pages/batch_actions.js - 304 Not Modified (4ms)
Served asset /active_admin/pages/application.js - 304 Not Modified (3ms)


Started GET "/assets/active_admin/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/application.js - 304 Not Modified (9ms)


Started GET "/assets/active_admin/base.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/base.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin.js - 304 Not Modified (0ms)


Started GET "/?order=id_desc&page=1&scope=in_progress" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
  User Load (1.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Processing by Admin::ServersController#index as HTML
  Parameters: "order"=>"id_desc", "page"=>"1", "scope"=>"in_progress"
  Tenant Load (2.4ms)  SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
   (2.6ms)  SELECT COUNT(*) FROM "servers" WHERE ('t')
   (4.3ms)  SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
   (2.8ms)  SELECT COUNT(*) FROM "servers" WHERE (build_stage = '7 - Build Team Remediation' OR build_stage = '13 - SecOps Remediation')
   (2.3ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
  CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
  CACHE (0.0ms)  SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
  CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
  Server Load (2.6ms)  SELECT "servers".* FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') ORDER BY "servers"."id" desc LIMIT 30 OFFSET 0
  Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (359.3ms)
Completed 200 OK in 373ms (Views: 349.4ms | ActiveRecord: 19.5ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600


Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /jquery-ui.js - 304 Not Modified (0ms)


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /jquery_ujs.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.checkbox-toggler.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.popover.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.popover.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/pages/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/pages/application.js - 304 Not Modified (0ms)
Served asset /jquery.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600


Started GET "/assets/active_admin/lib/namespace.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/application.js - 304 Not Modified (0ms)
Served asset /active_admin/lib/namespace.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.dropdown-menu.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.dropdown-menu.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/components/jquery.aa.table-checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.table-checkbox-toggler.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/pages/batch_actions.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/pages/batch_actions.js - 304 Not Modified (0ms)


Started GET "/assets/active_admin/base.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/base.js - 304 Not Modified (12ms)


Started GET "/assets/active_admin.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin.js - 304 Not Modified (0ms)

登录并在生产环境中按下过滤器按钮( GET "/?order=id_desc&page=1&scope=in_progress" )后:

Started POST "/users/sign_in" for 127.0.0.1 at 2013-12-29 19:47:10 -0600
Processing by Devise::SessionsController#create as HTML
  Parameters: "utf8"=>"✓", "authenticity_token"=>"UmLj+rzYzRWPr/Y7G5q2Y+/6KptI6X1EzoE7xJCjCIQ=", "user"=>"email"=>"moderator@example.com", "password"=>"[FILTERED]", "remember_me"=>"0", "commit"=>"Sign in"
Redirected to http://testdomain.warthog.dev/admin
Completed 302 Found in 116ms (ActiveRecord: 1.8ms)
Started GET "/admin" for 127.0.0.1 at 2013-12-29 19:47:11 -0600
Processing by Admin::ServersController#index as HTML
  Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (115.1ms)
Completed 200 OK in 126ms (Views: 97.7ms | ActiveRecord: 24.6ms)
Started GET "/?order=id_desc&page=1&scope=in_progress" for 127.0.0.1 at 2013-12-29 19:47:23 -0600
Processing by Devise::SessionsController#new as HTML
  Parameters: "order"=>"id_desc", "page"=>"1", "scope"=>"in_progress"
  Rendered devise/shared/_links.haml (0.3ms)
  Rendered devise/sessions/new.html.haml within layouts/application (3.2ms)
Completed 200 OK in 14ms (Views: 7.2ms | ActiveRecord: 4.4ms)
答案

在试用了托管版本之后,我认为问题出在用于对服务器表进行排序的链接中。 当前,您使用链接http://testdomain.dcmdashboard.com/?order=operating_system_desc来按操作系统对表进行排序。 如果您改用http://testdomain.dcmdashboard.com/admin/?order=operating_system_desc (在查询参数前面使用/ admin /),则会话不会被杀死,也不必再次登录。

仅在app/admin/servers.rb具有您自己定义的集合的那些列确实存在此问题。 它可能是active_admin当前开发版本中的错误或缺少参数。

请在config/initializers/active_admin.rb为默认名称空间添加一个值:

config.default_namespace = :admin

如果问题仍然存在,请尝试使用active_admin的稳定版本(如0.6.2版),然后重试。

另一答案

生产与开发之间的唯一区别是,当您跟踪使您退出/ admin名称空间的链接时,生产会将您注销,这两种情况都存在问题,它看起来像是ActiveAdmin错误。

与主动管理中的好人保持联系将有助于https://github.com/gregbell/active_admin/issues/2839

另外,虽然将ActiveAdmin用于非常简单的应用程序,并且脚手架很好并且可以,但是您会感到沮丧,因为您决定使用它进行任何复杂的工作,而在失去修复这一范围的时间中,您可能可以使用ransack和设计

以上是关于在生产模式中无意中破坏了Rails Devise会话的主要内容,如果未能解决你的问题,请参考以下文章

Devise只在数据库中写入本地IP地址

在 Rails 中使用 Devise 注销特定用户

Rails 4 + 设计:密码重置总是在生产服务器上给出“令牌无效”错误,但在本地工作正常。

无法在 Rails 中使用 Devise 销毁会话 [重复]

如何在 Ruby on Rails 中使用 Devise 验证密码强度?

rails - 设计 - 处理 - devise_error_messages