我使用的gem devise-token-auth效果很好。
目前,在注册时,我使用的原始路由是/api/v1/auth
:
# routes.rb
namespace :api do
namespace :v1 do
mount_devise_token_auth_for 'User', as: 'v1', at: 'auth', controllers: {
token_validations: 'api/v1/users/token_validations',
confirmations: 'api/v1/users/confirmations',
registrations: 'api/v1/users/registrations',
passwords: 'api/v1/users/passwords',
sessions: 'api/v1/users/sessions'
}
end
end
现在,我想例如更改/api/v1/auth/signing_up
的默认注册URL,但是当我将post
行添加到文件中时,即使rails routes
返回我想要的内容,我出现错误:
# routes.rb
post "/auth/signing_up" => "users/registrations#create"
# rails routes
# Default route
api_v1_user_registrationPOST /api/v1/auth(.:format) api/v1/users/registrations#create
# New created route
api_v1_auth_signing_up POST /api/v1/auth/signing_up(.:format) api/v1/users/registrations#create
# Error when POST
AbstractController::ActionNotFound (Could not find devise mapping for path "/api/v1/auth/signing_up".
答案 0 :(得分:0)
我将其用于其他类型的注册,并且效果很好
namespace :api, constraints: { format: 'json' } do
namespace :v1 do
devise_scope :user do
post 'auth/teacher_sign_up', to: 'registration#teacher_sign_up'
end
devise_scope :user do
post 'auth/student_sign_up', to: 'sessions#teacher_sign_up'
end
end
end