После выполнения вызова API PUT в / dashboard_users / update devise вернет мне сообщение об ошибке:
ActionController :: RoutingError (Нет совпадений маршрута [PUT] "/")
Здесьполная ошибка:
Started PUT "/dashboard_users" for ::1 at 2019-10-15 13:34:12 +0700
13:34:12 web.1 | (0.6ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
13:34:12 web.1 | ↳ /home/theo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
13:34:12 web.1 | Processing by RegistrationsController#update as HTML
13:34:12 web.1 | Parameters: {"dashboard_user"=>{"last_name"=>"Cerutti", "first_name"=>"Théo"}, "registration"=>{"dashboard_user"=>{"last_name"=>"Cerutti", "first_name"=>"Théo"}}}
13:34:12 web.1 | DashboardUser Load (0.8ms) SELECT `dashboard_users`.* FROM `dashboard_users` WHERE `dashboard_users`.`id` = 1 ORDER BY `dashboard_users`.`id` ASC LIMIT 1
13:34:12 web.1 | ↳ /home/theo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
13:34:12 web.1 | get_vendor succeeded on /get_vendor
13:34:12 web.1 | DashboardUser Load (0.3ms) SELECT `dashboard_users`.* FROM `dashboard_users` WHERE `dashboard_users`.`id` = 1 LIMIT 1
13:34:12 web.1 | ↳ /home/theo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
13:34:12 web.1 | (0.1ms) BEGIN
13:34:12 web.1 | ↳ app/controllers/registrations_controller.rb:26
13:34:12 web.1 | (0.2ms) COMMIT
13:34:12 web.1 | ↳ app/controllers/registrations_controller.rb:26
13:34:12 web.1 | Redirected to http://localhost:3000/
13:34:12 web.1 | Completed 302 Found in 62ms (ActiveRecord: 1.4ms)
13:34:12 web.1 |
13:34:12 web.1 |
13:34:12 web.1 | Started PUT "/" for ::1 at 2019-10-15 13:34:12 +0700
13:34:12 web.1 |
13:34:12 web.1 | ActionController::RoutingError (No route matches [PUT] "/"):
13:34:12 web.1 |
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
13:34:12 web.1 | web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
13:34:12 web.1 | web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
13:34:12 web.1 | web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
13:34:12 web.1 | web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
13:34:12 web.1 | railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
13:34:12 web.1 | railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
13:34:12 web.1 | activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
13:34:12 web.1 | activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
13:34:12 web.1 | activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
13:34:12 web.1 | railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
13:34:12 web.1 | sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
13:34:12 web.1 | rack (2.0.7) lib/rack/method_override.rb:22:in `call'
13:34:12 web.1 | rack (2.0.7) lib/rack/runtime.rb:22:in `call'
13:34:12 web.1 | activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
13:34:12 web.1 | actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
13:34:12 web.1 | rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
13:34:12 web.1 | webpacker (4.0.7) lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
13:34:12 web.1 | rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
13:34:12 web.1 | railties (5.2.3) lib/rails/engine.rb:524:in `call'
13:34:12 web.1 | puma (3.12.1) lib/puma/configuration.rb:227:in `call'
13:34:12 web.1 | puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
13:34:12 web.1 | puma (3.12.1) lib/puma/server.rb:474:in `process_client'
13:34:12 web.1 | puma (3.12.1) lib/puma/server.rb:334:in `block in run'
13:34:12 web.1 | puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Мой вызов API работает, потому что он обновляет моего пользователя. Я думаю, что формат ответа вызывает эту ошибку ..
РЕДАКТИРОВАТЬ: сторона клиента:
axios.put('http://localhost:3000/dashboard_users', data).then((res) => {
console.log(res);
}).catch((error) => {
console.log(error);
});
РЕДАКТИРОВАТЬ: найти странную вещь
Я создал RegistrationsController (наследуется deviseконтроллер):
# frozen_string_literal: true
class RegistrationsController < Devise::RegistrationsController
respond_to :json
protected
# override update_resource for updating user without password if no password passed
# else if password is given password will be updated
def update_resource(resource, params)
# Require current password if user is trying to change password.
return super if params['password']&.present?
# Allows user to update registration information without password.
resource.update_without_password(params.except('current_password'))
end
end
мой маршрут:
`devise_for :dashboard_users, controllers: { registrations: 'registrations' }, defaults: { format: 'json' }`
Если я укажу default: {format: 'json'} в моем маршруте и response_to: json в моем контроллере, мой вызов API нене делайте никаких ошибок!
НО мой другой маршрут, отображаемый с помощью представления (пример sign_in), при попытке доступа к нему создает ошибку UnknownFormatError.
Спасибо