我正在使用jsonapi-resources gem构建Rails 5 JSON API。我发现它很简单,除非我试图将它与Devise配对。我一直收到404错误。
我尝试将while
与设计Users::RegistrationResource
配对。这是我的代码。
应用/控制器/ application_controller.rb
Users::RegistrationsController
应用/控制器/用户/ registrations_controller.rb
class ApplicationController < ActionController::API
include JSONAPI::ActsAsResourceController
end
应用/资源/用户/ registration_resource.rb
class Users::RegistrationsController < Devise::RegistrationsController
include JSONAPI::ActsAsResourceController
end
配置/ routes.rb中
class Users::RegistrationResource < JSONAPI::Resource
model_name 'User'
attributes :email, :password, :password_confirmation
end
佣金路线
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
rails服务器
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
这是我在Postman发布的数据:
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]
):
我想在第一个例子中,这是路线的问题。有人可以帮忙吗?