2016-09-03 51 views
2

/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_upPostman

我的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,沒有什麼變化:(

我在做什麼錯誤?

+0

可能[bug](https://github.com/lynndylanhurley/devise_token_auth/issues/100)對於token-auth gem,但它已經被提出並且其狀態現在已關閉_they似乎試圖刪除這個路線,但然後讓它停留的某些原因聲明[這裏](http://stackoverflow.com/a/7042419)_! –

+0

['DeviseTokenAuth :: RegistrationsController'](https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/registrations_controller.rb)沒有任何新動作,這在你身上很有意義考慮基於令牌的身份驗證主要用於API或單頁應用程序,其中呈現新路線是在javascript中完成的,而不是在rails中完成的。 – max

+0

一般來說,在API應用程序中沒有「新建」或「編輯」操作,因爲您沒有在Web界面中使用渲染表單。對於API客戶端,GET/some_resource/new是毫無意義的。 – max

回答

1

由於devise_token_auth

的README文件中規定爲什麼在新航線包括如果該寶石不使用它們?

刪除新路線將需要對設計進行重大修改。如果包含新路由導致您的應用有任何 問題,請在問題跟蹤器中發佈問題,並儘快解決問題 。

newedit功能不是由devise_token_auth提供,但路線仍顯示他們的路線從devise_token_auth是在建devise和努力來撤消這些路線。

無論如何,基於API的應用程序通常不需要該功能,因爲該邏輯內置於API客戶端(例如:angular.js或react.js)。如果由於某種原因,您需要讓API客戶端知道createupdate所需的數據,您可以將其記錄下來,或者當API客戶端提供錯誤數據時,您可以提供必需的字段信息作爲錯誤的一部分。

相關問題