如何解决找不到针对路径的设计映射 Rails 6 +设计
我在routes.rb
中有下一条路线:
Rails.application.routes.draw do
namespace 'api' do
scope module: :v1,defaults: {format: 'json'} do
namespace 'users' do
devise_for :users,skip: :all
devise_scope :user do
post '/signup' => 'registrations#create',as: :user_registration
end
end
end
end
end
当我想通过邮递员发送POST查询时,
{
"user": {
"email": "example@email.com","password": "password","password_confirmation": "password"
}
}
我遇到下一个错误:
[Devise] Could not find devise mapping for path "/api/users/signup".
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 | Allocations: 183)
我的registrations_controller.rb
是:
class Api::V1::Users::RegistrationsController < Devise::RegistrationsController
respond_to :json
def create
build_resource(sign_up_params)
resource.save
render_resource(resource)
end
end
此外,发自rake routes
的POST:
api_users_user_registration POST /api/users/signup(.:format)
api/v1/users/registrations#create {:format=>"json"}
这很奇怪,因为以前它可以正常工作,但是在前端进行一些工作后就坏了。来自routes
的路由已在范围内。可能是我随机更改了某些内容。怎么了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。