/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
}
这是我所做的一切
创建了一个新的Rails API项目
rails new untitled --javascript=jquery --api
将此添加到Gemfile
#authentication
gem 'devise'
gem 'omniauth'
gem 'devise_token_auth'
以下
bundle install
rails generate devise_token_auth:install User auth
rails db:migrate
rails s
从浏览器和localhost:3000/auth/sign_up
Postman
我的routes.rb
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth'
end
我的铁路路线输出
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)
我注意到的其他事情
/auth/sign_in
完美无瑕地工作,并且我能够使用Rails Console
subdomain constraints
routes.rb
引起的。评论 >即使在做了回答后给出的内容没有摆脱404 这是我尝试过的事情
rails generate devise:controller users
new
RegistrationsController
部分
render :json
,它总是会抛出一个状态为200的空JSON,终端上出现奇怪的bin/rails: No such file or directory
错误rails app:update:bin
摆脱它,没有任何变化:(我做错了什么?
答案 0 :(得分:2)
如果这个宝石没有使用它们,为什么包含新路线?
删除新路线需要进行大量修改 设计。如果包含新路线导致您的应用程序任何 问题,在问题跟踪器中发布问题,它将得到解决 的ASAP。
new
未提供 edit
和devise_token_auth
功能,但路由仍会显示,因为路由来自devise
devise_token_auth
是create
建立起来并且难以撤消这些路线。
通常,对于基于API的应用程序,您根本不需要该功能,因为该逻辑内置于API客户端中(例如:angular.js或react.js)。如果由于某种原因,您需要让API客户端知道update
或rails generate scaffold User name:string email:string
所需的数据,您可以记录它或者当API客户端提供错误数据时,您可以提供必填字段信息作为错误的一部分。