首页 > 解决方案 > 使用设计令牌身份验证覆盖 Rails API 中的注册控制器时出现路由错误

问题描述

我正在尝试发送 POST 请求(使用 Postman)以使用设计令牌身份验证注册新用户,并且我正在覆盖注册控制器以启用我自己的 JSON 响应。

我不断收到路由错误:

"status": 404,
    "error": "Not Found",
    "exception": "#<ActionController::RoutingError: uninitialized constant Overrides>"

这是我的注册控制器:

module Api
  module V1
   module Overrides
     class RegistrationsController < DeviseTokenAuth::RegistrationsController

   respond_to :json
    def create

      user = User.new(params[:user])
      if user.save
        render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
        return
      else
        warden.custom_failure!
        render :json=> user.errors, :status=>422
       end
     end
    end
  end
 end
end

这是我的路线文件:

Rails.application.routes.draw do


  namespace :api do
   scope :v1 do
    mount_devise_token_auth_for 'User', at: 'auth', controllers: {

    registrations: 'overrides/registrations',
    sessions: 'overrides/sessions'

}
    end
  end
end

我的路线哪里出错了?

标签: ruby-on-railsrails-routingrails-apidevise-token-auth

解决方案


推荐阅读