Rails 5: разработка регистрации с возвратом jsonapi-ресурсов 404

Я строю Rails 5 JSON API с драгоценным камнем jsonapi. Я нашел его простым в использовании, за исключением того, что я пытался связать его с Devise. Я все время получаю ошибку 404.

Я попытался соединиться Users::RegistrationResourceс Devise Users::RegistrationsController. Вот код, который у меня есть.

приложение / контроллеры / application_controller.rb

class ApplicationController < ActionController::API
  include JSONAPI::ActsAsResourceController
end

приложение / контроллеры / пользователи / registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  include JSONAPI::ActsAsResourceController
end

приложение / ресурсы / пользователей / registration_resource.rb

class Users::RegistrationResource < JSONAPI::Resource
  model_name 'User'
  attributes :email, :password, :password_confirmation
end

конфиг / routes.rb

             Prefix Verb   URI Pattern                        Controller#Action
          auth_user POST   /auth_user(.:format)               authentication#authenticate_user
users_registrations GET    /users/registrations(.:format)     users/registrations#index
                    POST   /users/registrations(.:format)     users/registrations#create
 users_registration GET    /users/registrations/:id(.:format) users/registrations#show
                    PATCH  /users/registrations/:id(.:format) users/registrations#update
                    PUT    /users/registrations/:id(.:format) users/registrations#update
                    DELETE /users/registrations/:id(.:format) users/registrations#destroy

рейк-маршруты

users_registrations POST   /users/registrations(.:format)     users/registrations#create
          auth_user POST   /auth_user(.:format)               authentication#authenticate_user
                    GET    /users/registrations(.:format)     users/registrations#index
                    POST   /users/registrations(.:format)     users/registrations#create
 users_registration GET    /users/registrations/:id(.:format) users/registrations#show
                    PATCH  /users/registrations/:id(.:format) users/registrations#update
                    PUT    /users/registrations/:id(.:format) users/registrations#update
                    DELETE /users/registrations/:id(.:format) users/registrations#destroy
               root GET    /                                  pages#index

сервер rails

Started POST "/users/registrations" for ::1 at 2016-10-14 18:08:21 +0100
Processing by Users::RegistrationsController#create as */*
  Parameters: {"data"=>{"type"=>"users", "attributes"=>{"email"=>"neil@examples.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}}
[Devise] Could not find devise mapping for path "/users/registrations".
This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]


Completed 404 Not Found in 0ms (ActiveRecord: 0.0ms)



AbstractController::ActionNotFound (Could not find devise mapping for path "/users/registrations".
This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]

):

Это данные, которые я публикую в Postman:

POST http://localhost:3000/users/registrations
Content-Type application/vnd.api+json
{
 "data": {
    "type": "users",
    "attributes": {
        "email": "neil@examples.com",
        "password": "Whatevs",
        "password_confirmation": "Whatevs"
    }
  } 
}

Я предполагаю, что в первую очередь это проблема с маршрутами. Может ли кто-нибудь помочь?

ruby-on-rails,devise,ruby-on-rails-5,jsonapi-resources,

1

Ответов: 0

Rails 5: разработка регистрации с возвратом jsonapi-ресурсов 404

Я строю Rails 5 JSON API с драгоценным камнем jsonapi. Я нашел его простым в использовании, за исключением того, что я пытался связать его с Devise. Я все время получаю ошибку 404.

Я попытался соединиться Users::RegistrationResourceс Devise Users::RegistrationsController. Вот код, который у меня есть.

приложение / контроллеры / application_controller.rb

class ApplicationController < ActionController::API
  include JSONAPI::ActsAsResourceController
end

приложение / контроллеры / пользователи / registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  include JSONAPI::ActsAsResourceController
end

приложение / ресурсы / пользователей / registration_resource.rb

class Users::RegistrationResource < JSONAPI::Resource
  model_name 'User'
  attributes :email, :password, :password_confirmation
end

конфиг / routes.rb

             Prefix Verb   URI Pattern                        Controller#Action
          auth_user POST   /auth_user(.:format)               authentication#authenticate_user
users_registrations GET    /users/registrations(.:format)     users/registrations#index
                    POST   /users/registrations(.:format)     users/registrations#create
 users_registration GET    /users/registrations/:id(.:format) users/registrations#show
                    PATCH  /users/registrations/:id(.:format) users/registrations#update
                    PUT    /users/registrations/:id(.:format) users/registrations#update
                    DELETE /users/registrations/:id(.:format) users/registrations#destroy

рейк-маршруты

users_registrations POST   /users/registrations(.:format)     users/registrations#create
          auth_user POST   /auth_user(.:format)               authentication#authenticate_user
                    GET    /users/registrations(.:format)     users/registrations#index
                    POST   /users/registrations(.:format)     users/registrations#create
 users_registration GET    /users/registrations/:id(.:format) users/registrations#show
                    PATCH  /users/registrations/:id(.:format) users/registrations#update
                    PUT    /users/registrations/:id(.:format) users/registrations#update
                    DELETE /users/registrations/:id(.:format) users/registrations#destroy
               root GET    /                                  pages#index

сервер rails

Started POST "/users/registrations" for ::1 at 2016-10-14 18:08:21 +0100
Processing by Users::RegistrationsController#create as */*
  Parameters: {"data"=>{"type"=>"users", "attributes"=>{"email"=>"neil@examples.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}}
[Devise] Could not find devise mapping for path "/users/registrations".
This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]


Completed 404 Not Found in 0ms (ActiveRecord: 0.0ms)



AbstractController::ActionNotFound (Could not find devise mapping for path "/users/registrations".
This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]

):

Это данные, которые я публикую в Postman:

POST http://localhost:3000/users/registrations
Content-Type application/vnd.api+json
{
 "data": {
    "type": "users",
    "attributes": {
        "email": "neil@examples.com",
        "password": "Whatevs",
        "password_confirmation": "Whatevs"
    }
  } 
}

Я предполагаю, что в первую очередь это проблема с маршрутами. Может ли кто-нибудь помочь?

01рубин-на-рельсы, завещать, рубин-на-рельсы-5, jsonapi-ресурсов,
Похожие вопросы