设计注册路由不存在

Joh*_*Cdf 1 api ruby-on-rails devise

我目前正在我的 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)
Run Code Online (Sandbox Code Playgroud)

我的文件如下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
Run Code Online (Sandbox Code Playgroud)

我正在覆盖会话/注册,使用我自己的,如下所示:

会话控制器

# 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
Run Code Online (Sandbox Code Playgroud)

注册控制器

# 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
Run Code Online (Sandbox Code Playgroud)

Roc*_*ice 5

您需要:registerable在用户模型中添加。我不确定您的模型是什么样子,但在要包含的设计模块组中确保: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
Run Code Online (Sandbox Code Playgroud)