/auth/sign_up
上的GET未按預期運行。得到以下404錯誤Rails 5 AbstractController :: ActionNotFound:無法爲[GET]「/ auth/sign_up」上的DeviseTokenAuth :: RegistrationsController找到操作'new'
{
"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
-
看起來像一個類似的錯誤導致此 post創建的用戶,但沒有造成routes.rb
有的因subdomain constraints
已在評論提到甚至像做什麼的答案給出沒有擺脫404
這裏後是我的嘗試再
- 試圖
rails generate devise:controller users
- Uuncommmented
new
部分RegistrationsController
- 增加了一些隨機
render :json
S的總是與狀態200怪異bin/rails: No such file or directory
錯誤的終端 - 試圖拋出了一個空的JSON開始使用擺脫它
rails app:update:bin
,沒有什麼變化:(
我在做什麼錯誤?
可能[bug](https://github.com/lynndylanhurley/devise_token_auth/issues/100)對於token-auth gem,但它已經被提出並且其狀態現在已關閉_they似乎試圖刪除這個路線,但然後讓它停留的某些原因聲明[這裏](http://stackoverflow.com/a/7042419)_! –
['DeviseTokenAuth :: RegistrationsController'](https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/registrations_controller.rb)沒有任何新動作,這在你身上很有意義考慮基於令牌的身份驗證主要用於API或單頁應用程序,其中呈現新路線是在javascript中完成的,而不是在rails中完成的。 – max
一般來說,在API應用程序中沒有「新建」或「編輯」操作,因爲您沒有在Web界面中使用渲染表單。對於API客戶端,GET/some_resource/new是毫無意義的。 – max