我目前正在使用Rails API应用上的devise
插件来实现devise-jwt
。
我已经添加了设计所需的配置,但是当涉及到路由时,似乎不存在注册路由...
运行rails routes
时得到以下输出:
new_user_session GET /login(.:format) sessions#new
user_session POST /login(.:format) sessions#create
destroy_user_session DELETE /logout(.:format)
这是我的app/config/routes.rb
文件的样子:
Rails.application.routes.draw do
devise_for :users,
path: '',
path_names: {
sign_in: 'login',
sign_out: 'logout',
registration: 'signup'
},
# i use my own custom controllers for this
controllers: {
sessions: 'sessions',
registrations: 'registrations'
}
end
我使用自己的方法来覆盖会话/注册:
# app/controllers/sessions_controller.rb
class SessionsController < Devise::SessionsController
private
def respond_with(resource, _opts = {})
render json: resource
end
def response_to_on_destroy
head :no_content
end
end
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
respond_to :json
def create
build_resource(sign_up_params)
resource.save
render_resource(resource)
end
end
答案 0 :(得分:1)
您需要在用户模型内添加:registerable
。我不确定您的模型是什么样子,但在Devise模块组中是否要包含:registerable
即可。
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, <-- This one
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable