[英]Rails with Devise in production mode No route matches [GET] “/users/sign_out”
I realize that this question has been asked a few times. 我意识到这个问题已经问过几次了。 But I have tried all of the solutions discussed on other threads and none of them have worked for me. 但是我尝试了在其他线程上讨论的所有解决方案,但没有一个对我有用。
I am using rails v5.2.1 and ruby v2.4.1 with devise 我正在使用devise的 Rails v5.2.1和ruby v2.4.1
My application works absolutely fine in development mode. 我的应用程序在开发模式下工作正常。 As soon as I switch to production, my logout link fails with No route matches [GET] "/users/sign_out" 切换到生产环境后,我的注销链接会失败,并且没有路由匹配[GET]“ / users / sign_out”
My logout link should trigger a DELETE not a GET 我的注销链接应触发DELETE而不是GET
<%= link_to('Logout', destroy_user_session_path, method: :delete) %>
Here are my routes 这是我的路线
$rake routes | grep sign_out
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
I have precompiled my assets with 我已经用
rake assets:clobber RAILS_ENV=production
rake assets:precompile RAILS_ENV=production
I have tried the following configuration options in various combinations 我已经尝试了以下配置选项的各种组合
# devise.rb
config.sign_out_via = :delete
# production.rb
config.public_file_server.enabled = true
config.assets.compile = true
I'm pretty new to rails and this is the first time I'm creating a production environment. 我对Rails很陌生,这是我第一次创建生产环境。 So I may be making a very basic mistake, but I haven't been able to figure it out 所以我可能犯了一个非常基本的错误,但我无法弄清楚
Here is the full contents of the logs triggered by clicking the sign_out link 这是单击sign_out链接触发的日志的全部内容
INFO -- : [55a64c1a-feb0-45bb-a8e8-5e3bf5efe461] Started GET "/users/sign_out" for 127.0.0.1 at 2018-09-15 17:02:20 +0200
FATAL -- : [55a64c1a-feb0-45bb-a8e8-5e3bf5efe461]
FATAL -- : [55a64c1a-feb0-45bb-a8e8-5e3bf5efe461] ActionController::RoutingError (No route matches [GET] "/users/sign_out"):
FATAL -- : [55a64c1a-feb0-45bb-a8e8-5e3bf5efe461]
FATAL -- : [55a64c1a-feb0-45bb-a8e8-5e3bf5efe461] actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
For what it's worth, the rest of my pages keep throwing up these errors about being unable to find my assets. 值得的是,我的其余页面不断抛出关于找不到我的资产的错误。 I can't seem to clear those errors either. 我似乎也无法清除这些错误。 I have recompiled my assets many times and also gone through many different documents about them. 我已经多次重新编译了我的资产,还浏览了许多有关它们的文档。 As far as I can see it should work 据我所知它应该工作
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Started GET
"/control_panels" for 127.0.0.1 at 2018-09-15 17:13:15 +0200
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Processing by
ControlPanelsController#index as HTML
DEBUG -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] [1m[36mUser Load (1.0ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2[0m [["id", 980190963], ["LIMIT", 1]]
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Rendering control_panels/index.html.erb within layouts/application
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Rendered control_panels/_index.erb (1.2ms)
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Rendered control_panels/index.html.erb within layouts/application (1.6ms)
INFO -- : [599f3a59-d3b1-4e0b-a974-a27abda77a0e] Completed 200 OK in 25ms (Views: 3.9ms | ActiveRecord: 1.0ms)
INFO -- : [efbfb389-6227-4e34-bd72-f4febeecf5c2] Started GET "/assets/application-35729bfbaf9967f119234595ed222f7ab14859f304ab0acc5451afb387f637fa.css" for 127.0.0.1 at 2018-09-15 17:13:15 +0200
FATAL -- : [efbfb389-6227-4e34-bd72-f4febeecf5c2]
FATAL -- : [efbfb389-6227-4e34-bd72-f4febeecf5c2] ActionController::RoutingError (No route matches [GET] "/assets/application-35729bfbaf9967f119234595ed222f7ab14859f304ab0acc5451afb387f637fa.css"):
FATAL -- : [efbfb389-6227-4e34-bd72-f4febeecf5c2]
FATAL -- : [efbfb389-6227-4e34-bd72-f4febeecf5c2] actionpack (5.2.1)
lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
actionpack (5.2.1)
lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in
`block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in
`tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in
`tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in
`call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.1)
lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'```
As you already correctly pointed out, the route is for the DELETE
method, so a GET
request triggers a 404. The link_to
helper not working with the method:
option usually means that Javascript is disabled in your browser. 正如您已经正确指出的那样,该路由用于DELETE
方法,因此GET
请求将触发link_to
帮助程序无法与method:
选项一起使用通常意味着在浏览器中禁用了Javascript。 To be on the safe side, use button_to
instead of link_to
. 为了安全起见,请使用button_to
而不是link_to
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.