Rails&Devise:两步确认路由错误

我正在尝试使用Devise进行像heroku这样的两步确认。

我的路线:

devise_for :user, :controllers => {:confirmations => "confirmations", :registrations => "registrations" } put "confirm_account", :to => "confirmations#confirm_account" 

这是我的备用确认控制器:

 class ConfirmationsController  "show" end end end 

这是我的show.html.erb

  resource_name, :url => confirm_account_path(resource_name)) do |f| %>           'devise/shared/links' %>  

填写密码后单击确认(在确认电子邮件中单击confirm后)。 我被路由到/confirm_account.user这很奇怪,对吧? 是什么导致了这个问题?

编辑

rake routes返回:

  new_user_session GET /user/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"} user_session POST /user/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"} destroy_user_session GET /user/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"} user_password POST /user/password(.:format) {:action=>"create", :controller=>"devise/passwords"} new_user_password GET /user/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"} edit_user_password GET /user/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"} PUT /user/password(.:format) {:action=>"update", :controller=>"devise/passwords"} cancel_user_registration GET /user/cancel(.:format) {:action=>"cancel", :controller=>"registrations"} user_registration POST /user(.:format) {:action=>"create", :controller=>"registrations"} new_user_registration GET /user/sign_up(.:format) {:action=>"new", :controller=>"registrations"} edit_user_registration GET /user/edit(.:format) {:action=>"edit", :controller=>"registrations"} PUT /user(.:format) {:action=>"update", :controller=>"registrations"} DELETE /user(.:format) {:action=>"destroy", :controller=>"registrations"} user_confirmation POST /user/confirmation(.:format) {:action=>"create", :controller=>"confirmations"} new_user_confirmation GET /user/confirmation/new(.:format) {:action=>"new", :controller=>"confirmations"} GET /user/confirmation(.:format) {:action=>"show", :controller=>"confirmations"} user_unlock POST /user/unlock(.:format) {:action=>"create", :controller=>"devise/unlocks"} new_user_unlock GET /user/unlock/new(.:format) {:action=>"new", :controller=>"devise/unlocks"} GET /user/unlock(.:format) {:action=>"show", :controller=>"devise/unlocks"} confirm_account PUT /confirm_account(.:format) {:action=>"confirm_account", :controller=>"confirmations"} editreject_admin GET /admin/:id/editreject(.:format) {:action=>"editreject", :controller=>"admin"} reject_admin GET /admin/:id/reject(.:format) {:action=>"reject", :controller=>"admin"} accept_admin GET /admin/:id/accept(.:format) {:action=>"accept", :controller=>"admin"} entries_admin_index GET /admin/entries(.:format) {:action=>"entries", :controller=>"admin"} preferences_admin_index GET /admin/preferences(.:format) {:action=>"preferences", :controller=>"admin"} admin_index GET /admin(.:format) {:action=>"index", :controller=>"admin"} about_entries GET /entries/about(.:format) {:action=>"about", :controller=>"entries"} all_entries GET /entries/all(.:format) {:action=>"all", :controller=>"entries"} myentries_entries GET /entries/myentries(.:format) {:action=>"myentries", :controller=>"entries"} rate_entry GET /entries/:id/rate(.:format) {:action=>"rate", :controller=>"entries"} submit_entry PUT /entries/:id/submit(.:format) {:action=>"submit", :controller=>"entries"} entry_comments POST /entries/:entry_id/comments(.:format) {:action=>"create", :controller=>"comments"} entry_comment DELETE /entries/:entry_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"} entries GET /entries(.:format) {:action=>"index", :controller=>"entries"} POST /entries(.:format) {:action=>"create", :controller=>"entries"} new_entry GET /entries/new(.:format) {:action=>"new", :controller=>"entries"} edit_entry GET /entries/:id/edit(.:format) {:action=>"edit", :controller=>"entries"} entry GET /entries/:id(.:format) {:action=>"show", :controller=>"entries"} PUT /entries/:id(.:format) {:action=>"update", :controller=>"entries"} DELETE /entries/:id(.:format) {:action=>"destroy", :controller=>"entries"} /auth/:service/callback(.:format) {:controller=>"services", :action=>"create"} services GET /services(.:format) {:action=>"index", :controller=>"services"} POST /services(.:format) {:action=>"create", :controller=>"services"} root /(.:format) {:controller=>"entries", :action=>"index"} offline /offline(.:format) {:controller=>"application", :action=>"offline"} 

编辑3改变

  devise_for :user, :controllers => {:confirmations => "confirmations", :registrations => "registrations" } do match "/confirm_account", :to => "confirmations#confirm_account" end 

我收到了:

当你没想到它时,你有一个零对象! 您可能期望一个Array实例。 在评估nil时发生错误。[]

 {"utf8"=>"✓", "authenticity_token"=>"dsG/e8Tw2Oi6zEDb07R/L0yDOKFEFlse+IgLbfz3Lo0=", "user"=>{"confirmation_token"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Confirm Account"} 

url中肯定有一个令牌,但是……实际上它正在某个地方!

它看起来像confirm_account_path不存在?

如果您没有手动设置路由,可以继续在config/routes.rb文件中将其设置为confirmations#confirm_account config/routes.rb

或者,如果您将Devise设置为使用ConfirmationsController ,则使用new_user_confirmation_path也可能有效(也可能不会)。 在控制台中键入rake routes以查看可用路由。 它们应该导致ConfirmationsControllerconfirm_account操作。

编辑:尝试编辑您的路线文件,如下所示。

 devise_for :user, :controllers => {:confirmations => "confirmations", :registrations => "registrations" } do match "/confirm_account" => "confirmations#confirm_account" end 

认为斜线在confirm_account之前很重要,因为它现在位于devise_for块内(与devise_scope相同)。 否则它可能会转到users/confirm_account

EDIT2:在控制器中使用params[:user][:confirmation_token] ,而不是params[:account][:confirmation_token] 。 但目前看起来确认令牌是空白的。