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
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"
My logout link should trigger a DELETE not a 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. 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
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.
To be on the safe side, use button_to
instead of link_to
.