Итак, для любого, кто действительно сталкивается с той же проблемой, у меня есть решение (см. Ниже).
Но мой вопрос: «Что вызывает это?» Почему метод Devise : delete не работает для sign_out (но : destroy метод работает)
Решение до применения: сбой при выходе из системы (с помощью: метод удаления)
web_1 | Started POST "/logout" for 172.25.0.1 at 2020-01-16 09:28:44 +0000
web_1 | Cannot render console from 172.25.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1 |
web_1 | ActionController::RoutingError (No route matches [POST] "/logout"):
web_1 |
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web_1 | web-console (3.6.2) lib/web_console/middleware.rb:135:in `call_app'
web_1 | web-console (3.6.2) lib/web_console/middleware.rb:22:in `block in call'
web_1 | web-console (3.6.2) lib/web_console/middleware.rb:20:in `catch'
web_1 | web-console (3.6.2) lib/web_console/middleware.rb:20:in `call'
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web_1 | railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
web_1 | railties (5.2.0) lib/rails/rack/logger.rb:28:in `call'
web_1 | sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
web_1 | rack (2.0.5) lib/rack/method_override.rb:22:in `call'
web_1 | rack (2.0.5) lib/rack/runtime.rb:22:in `call'
web_1 | activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1 | actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
web_1 | rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
web_1 | railties (5.2.0) lib/rails/engine.rb:524:in `call'
web_1 | puma (3.11.4) lib/puma/configuration.rb:225:in `call'
web_1 | puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
web_1 | puma (3.11.4) lib/puma/server.rb:446:in `process_client'
web_1 | puma (3.11.4) lib/puma/server.rb:306:in `block in run'
web_1 | puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Решение до применения: успех при destroy end_user (через: метод delete)
web_1 | Started DELETE "/end_user" for 172.25.0.1 at 2020-01-16 09:20:01 +0000
web_1 | Cannot render console from 172.25.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1 | Processing by EndUsers::RegistrationsController#destroy as HTML
web_1 | Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ycapv7HYDWdWNsG/Aqdpm+mqWG4CImp6bKOrzjRW1+jdbccoMvspCuo35NVNHPrZs0WN8BxFvVAEu9wBostcog==", "end_user"=>{"current_password"=>"[FILTERED]"}}
web_1 | EndUser Load (0.3ms) SELECT `end_users`.* FROM `end_users` WHERE `end_users`.`id` = 71 ORDER BY `end_users`.`id` ASC LIMIT 1
web_1 | EndUser Load (0.3ms) SELECT `end_users`.* FROM `end_users` WHERE `end_users`.`id` = 71 LIMIT 1
web_1 | (0.2ms) BEGIN
web_1 | EuPhoneNumber Load (0.5ms) SELECT `eu_phone_numbers`.* FROM `eu_phone_numbers` WHERE `eu_phone_numbers`.`end_user_id` = 71
web_1 | EuEmailAddress Load (0.5ms) SELECT `eu_email_addresses`.* FROM `eu_email_addresses` WHERE `eu_email_addresses`.`end_user_id` = 71
web_1 | EuAddress Load (0.4ms) SELECT `eu_addresses`.* FROM `eu_addresses` WHERE `eu_addresses`.`end_user_id` = 71
web_1 | EndUser Destroy (0.4ms) DELETE FROM `end_users` WHERE `end_users`.`id` = 71
web_1 | (1.8ms) COMMIT
web_1 | ActiveStorage::Attachment Load (0.4ms) SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 71 AND `active_storage_attachments`.`record_type` = 'EndUser' AND `active_storage_attachments`.`name` = 'profile_pic' LIMIT 1
web_1 | Redirected to http://localhost:3000/login
web_1 | Completed 302 Found in 119ms (ActiveRecord: 4.8ms)
Маршруты
Prefix Verb URI Pattern Controller#Action
new_end_user_session GET /login(.:format) end_users/sessions#new
end_user_session POST /login(.:format) end_users/sessions#create
destroy_end_user_session POST /logout(.:format) end_users/sessions#destroy
new_end_user_password GET /password/new(.:format) end_users/passwords#new
edit_end_user_password GET /password/edit(.:format) end_users/passwords#edit
end_user_password PATCH /password(.:format) end_users/passwords#update
PUT /password(.:format) end_users/passwords#update
POST /password(.:format) end_users/passwords#create
cancel_end_user_registration GET /cancel(.:format) end_users/registrations#cancel
new_end_user_registration GET /sign_up(.:format) end_users/registrations#new
edit_end_user_registration GET /edit(.:format) end_users/registrations#edit
end_user_registration PATCH / end_users/registrations#update
PUT / end_users/registrations#update
DELETE / end_users/registrations#destroy
POST / end_users/registrations#create
end_user_settings GET /settings(.:format) end_users/registrations#edit
end_user_settings_tab GET /settings/:tab(.:format) end_users/registrations#edit
end_user_register GET /register(.:format) end_users/sessions#new
destroy_end_user DELETE /end_user(.:format) end_users/registrations#destroy
end_user_update_password PUT /updatepassword(.:format) end_users/registrations#updatepassword
registration POST /register(.:format) end_users/registrations#create
new_user_session GET /app/login(.:format) users/sessions#new
user_session POST /app/login(.:format) users/sessions#create
destroy_user_session POST /app/logout(.:format) users/sessions#destroy
new_user_password GET /app/password/new(.:format) users/passwords#new
edit_user_password GET /app/password/edit(.:format) users/passwords#edit
user_password PATCH /app/password(.:format) users/passwords#update
PUT /app/password(.:format) users/passwords#update
POST /app/password(.:format) users/passwords#create
cancel_user_registration GET /app/cancel(.:format) users/registrations#cancel
new_user_registration GET /app/sign_up(.:format) users/registrations#new
edit_user_registration GET /app/edit(.:format) users/registrations#edit
user_registration PATCH /app(.:format) users/registrations#update
PUT /app(.:format) **users/registrations#update
DELETE /app(.:format) users/registrations#destroy**
POST /app(.:format) users/registrations#create
user_settings GET /app/settings(.:format) users/registrations#edit
user_settings_tab GET /app/settings/:tab(.:format) users/registrations#edit
user_update_password PUT /app/updatepassword(.:format) users/registrations#updatepassword
Разработка версии
* devise (4.4.3)
Версия Rails
* rails (5.2.0)
Решение: Измените метод sign_out с помощью файла devise.rb , находящегося в папке config / initializers .
# The default HTTP method used to sign out a resource. Default is :delete.
- config.sign_out_via = :delete
+ # config.sign_out_via = :delete
+ config.sign_out_via = :post
Тогда, когда у вас есть ссылки на sign_out, вам нужно заменить их кнопками, заменив link_to на button_to:
- <%= link_to('Logout', destroy_end_user_session_path, :method => :delete, :class => "dropdown-item") %>
+ <%= button_to('Logout', destroy_end_user_session_path, :method => :delete, :class => "dropdown-item hasaction") %>
или чисто html (добавьте маркер CSRF при необходимости):
- <a href="/app/logout" data-method='delete'>
- <i className="fas fa-sign-out"></i>
- <span className="nav-label">Logout</span>
- </a>
+ <form action="/app/logout" method="post">
+ <button type="submit" className="btn-plain text-left hasaction">
+ <i className="fas fa-sign-out"></i>
+ <span className="nav-label">Logout</span>
+ <input type="hidden" name="authenticity_token" value={this.state.csrf_token} />
+ </button>
+ </form>
Примечание: на вышеприведенных маршрутах решение до сих пор применялось только к методу sign_out