2016-12-21 72 views
0

我目前正在使用此鏈接的Rails API的JWT身份驗證: https://github.com/nsarno/knock 我仔細地遵循了她的指示。但是,我仍然無法使用剛纔註冊的用戶名和密碼登錄。我可以沒有錯誤登記,並告訴我這個消息:沒有路由匹配[POST]「/ knock/user_token」

Started POST "/users" for ::1 at 2016-12-20 22:28:32 -0500 
Processing by UsersController#create as HTML 
    Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}} 
    (0.4ms) BEGIN 
    SQL (0.8ms) INSERT INTO "users" ("email", "password_digest", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["email", "[email protected]"], ["password_digest", "$2a$10$1UAPAV92l.pHhbT.L3BvfOP7ieuy9yU2cdWdwy9VsVnTHjaRECB0W"], ["created_at", 2016-12-21 03:28:32 UTC], ["updated_at", 2016-12-21 03:28:32 UTC]] 
    (28.7ms) COMMIT 
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (1.42ms) 
Completed 200 OK in 162ms (Views: 21.2ms | ActiveRecord: 34.3ms) 

不過,我得到這個錯誤,如果我只用用戶名登錄名和密碼我註冊:

Started POST "/knock/user_token" for ::1 at 2016-12-20 22:29:02 -0500 

ActionController::RoutingError (No route matches [POST] "/knock/user_token"): 

這裏是路線.rb

Rails.application.routes.draw do 
    resources :cars 
    get '/users/current-user', to: "current_user#show" 
    resources :users 
    mount Knock::Engine => "/knock" 
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 
end 

這裏是耙路的輸出| grep的敲

  knock  /knock      Knock::Engine 
auth_token POST /auth_token(.:format) knock/auth_token#create 

這裏是routers.rb

Rails.application.routes.draw do 
    post 'user_token' => 'user_token#create' 
    resources :cars 
    get '/users/current-user', to: "current_user#show" 
    resources :users 
    mount Knock::Engine => "/knock" 
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 
end 

我該如何解決這個問題的配置?

+0

請發佈'routes.rb'。 – 31piy

+0

@ 31piy已發佈。我只是按照她的指示 –

+0

請寄出'rake routes | grep knock' – unkmas

回答

0

好的,我已經閱讀了這個寶石的文檔。

默認情況下沒有這樣的路線。當你安裝這個gem,你應該爲你的應用程序生成的令牌控制:該命令的

rails generate knock:token_controller user

輸出:

create app/controllers/user_token_controller.rb 
route post 'user_token' => 'user_token#create' 

正如你所看到的,令牌控制器被創造,也路線它。

+0

我試過了,我可以生成token_controller。但我得到了同樣的錯誤 –

+0

@ D.Kenny這很奇怪。請添加你的新routes.rb。已經添加 – unkmas

+0

。新年快樂 –