1

jsonapi-resources gem を使用して Rails 5 JSON API を構築しています。Deviseとペアリングしようとしたことを除いて、使いやすいことがわかりました。404 エラーが発生し続けます。

Users::RegistrationResourceaと 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

app/resources/users/registration_resource.rb

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

config/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

レールサーバー

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"
    }
  } 
}

最初の例では、ルートに問題があると思います。誰でも助けることができますか?

4

0 に答える 0