Rails 5 AbstractController::ActionNotFound:在 [GET]“/auth/sign_up”上找不到 DeviseTokenAuth::RegistrationsController 的操作 'new'

Rails 5 AbstractController::ActionNotFound: The action 'new' could not be found for DeviseTokenAuth::RegistrationsController on [GET] "/auth/sign_up"

/auth/sign_up 上的 GET 未按预期运行。得到以下 404 错误

{
    "status": 404,
    "error": "Not Found",
    "exception": "#<AbstractController::ActionNotFound: The action 'new' could not be found for DeviseTokenAuth::RegistrationsController>",
    "traces": #too long to post; 46 traces; none includes user created files
}

这是我所做的一切

我的routes.rb

Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth'
end

我的rails路线输出

              Prefix Verb     URI Pattern                            Controller#Action
        new_user_session GET      /auth/sign_in(.:format)                devise_token_auth/sessions#new
            user_session POST     /auth/sign_in(.:format)                devise_token_auth/sessions#create
    destroy_user_session DELETE   /auth/sign_out(.:format)               devise_token_auth/sessions#destroy
           user_password POST     /auth/password(.:format)               devise_token_auth/passwords#create
       new_user_password GET      /auth/password/new(.:format)           devise_token_auth/passwords#new
      edit_user_password GET      /auth/password/edit(.:format)          devise_token_auth/passwords#edit
                         PATCH    /auth/password(.:format)               devise_token_auth/passwords#update
                         PUT      /auth/password(.:format)               devise_token_auth/passwords#update
cancel_user_registration GET      /auth/cancel(.:format)                 devise_token_auth/registrations#cancel
       user_registration POST     /auth(.:format)                        devise_token_auth/registrations#create
   new_user_registration GET      /auth/sign_up(.:format)                devise_token_auth/registrations#new
  edit_user_registration GET      /auth/edit(.:format)                   devise_token_auth/registrations#edit
                         PATCH    /auth(.:format)                        devise_token_auth/registrations#update
                         PUT      /auth(.:format)                        devise_token_auth/registrations#update
                         DELETE   /auth(.:format)                        devise_token_auth/registrations#destroy
       user_confirmation POST     /auth/confirmation(.:format)           devise_token_auth/confirmations#create
   new_user_confirmation GET      /auth/confirmation/new(.:format)       devise_token_auth/confirmations#new
                         GET      /auth/confirmation(.:format)           devise_token_auth/confirmations#show
     auth_validate_token GET      /auth/validate_token(.:format)         devise_token_auth/token_validations#validate_token
            auth_failure GET      /auth/failure(.:format)                devise_token_auth/omniauth_callbacks#omniauth_failure
                         GET      /auth/:provider/callback(.:format)     devise_token_auth/omniauth_callbacks#omniauth_success
                         GET|POST /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
        omniauth_failure GET|POST /omniauth/failure(.:format)            devise_token_auth/omniauth_callbacks#omniauth_failure
                         GET      /auth/:provider(.:format)              redirect(301)

我注意到的其他事情

Here's what I tried then

  • 尝试过rails generate devise:controller users
  • RegistrationsController
  • 中未注释 new 部分
  • 添加了一些随机 render :jsons,它总是在终端
  • 上抛出状态为 200 的空 JSON 和奇怪的 bin/rails: No such file or directory 错误
  • 尝试使用 rails app:update:bin 摆脱它,没有任何变化:(

我做错了什么?

devise_token_auth

的 README 文档中所述

Why are the new routes included if this gem doesn't use them?

Removing the new routes will require significant modifications to devise. If the inclusion of the new routes is causing your app any problems, post an issue in the issue tracker and it will be addressed ASAP.

newedit 功能未由 devise_token_auth 提供,但路线仍会显示它们,因为路线来自 devise,其中 devise_token_auth 建立在这些路线之上并且很难撤消这些路线。

对于基于 API 的应用程序,通常您不需要该功能,因为该逻辑内置于 API 客户端(例如:angular.js 或 react.js).如果出于某种原因,您需要让 API 客户端知道 createupdate 所需的数据,您可以将其记录下来,或者当 API 客户端提供错误数据时,您可以提供必填字段信息作为错误的一部分。