设计注册路线不存在

时间:2018-10-07 23:44:02

标签: ruby-on-rails api 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)

这是我的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

1 个答案:

答案 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
相关问题