2014-09-29 114 views
1

我知道,我可以在我的应用程序创建PasswordsController下面这个wiki How To: Redirect URL after sending reset password instructions重定向发送重置密码的指令后,制定

我的问题是:

为什么我不能移动after_sending_reset_password_instructions_path_for(resource_name)方法ApplicationController中的样子:

protected 
# works 
def after_sign_in_path_for(resource) 
    root_path  
end 

# works 
def after_sign_out_path_for(resource_or_scope) 
    root_path 
end 

# doesn't work  
def after_sending_reset_password_instructions_path_for(resource_name) 
    user_login_path 
end 

还是重定向到默认路径localhost:3000/users/sign_in

我敢肯定我有user_login_path在我的routes.rb

devise_scope :user do 
    get '/register' => 'devise/registrations#new', :as => :user_register 
    get '/user/login' => 'devise/sessions#new', :as => :user_login 
    delete '/user/logout' => 'devise/sessions#destroy', :as => :user_logout 
    get '/forgot' => 'devise/passwords#new', :as => :user_forgot 
    post '/send/instruction' => 'devise/passwords#create', :as => :forgot_instructions 
    get '/new/password' => 'devise/passwords#edit', :as => :forgot_new 
    put '/update/password' => 'devise/passwords#update', :as => :forgot_update 
end 

而且该堆栈跟踪当我发送指令重置密码:

Started POST "/send/instruction" for 127.0.0.1 at 2014-09-29 16:32:12 +0700 
Processing by Devise::PasswordsController#create as HTML 
    Parameters: {"utf8"=>"V", "authenticity_token"=>"S7AppqJSUKat7GwhH8U/VhzQXvibiSaM1z6QJi+aP8s=", "u 
ser"=>{"email"=>"[email protected]"}, "commit"=>"Send me reset password instructions"} 
    ←[1m←[35mUser Load (3.0ms)←[0m SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected] 
gmail.com' ORDER BY "users"."id" ASC LIMIT 1 
    ←[1m←[36mUser Load (1.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "users"."reset_password_ 
token" = 'ee0dd49a2d7e4ba688e08ddebe40399c8f5a59ae5d8083621c35be09adf4aa65' ORDER BY "users"."id" A 
SC LIMIT 1←[0m 
    ←[1m←[35m (1.0ms)←[0m BEGIN 
    ←[1m←[36mSQL (0.0ms)←[0m ←[1mUPDATE "users" SET "reset_password_sent_at" = $1, "reset_password_to 
ken" = $2, "updated_at" = $3 WHERE "users"."id" = 2←[0m [["reset_password_sent_at", "2014-09-29 09: 
32:13.779043"], ["reset_password_token", "ee0dd49a2d7e4ba688e08ddebe40399c8f5a59ae5d8083621c35be09ad 
f4aa65"], ["updated_at", "2014-09-29 09:32:13.780043"]] 
    ←[1m←[35m (11.0ms)←[0m COMMIT 
    Rendered devise/mailer/reset_password_instructions.html.erb (1.0ms) 

Devise::Mailer#reset_password_instructions: processed outbound mail in 119.0ms 

Sent mail to [email protected] (5611.3ms) 
Date: Mon, 29 Sep 2014 16:32:13 +0700 
From: [email protected] 
Reply-To: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: Reset password instructions 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

<p>Hello [email protected]!</p> 

<p>Someone has requested a link to change your password. You can do this through the link below.</p> 


<p><a href="http://localhost:3000/new/password?reset_password_token=y4od6w4JsDnWeUbHTkyp">Cha 
nge my password</a></p> 

<p>If you didn't request this, please ignore this email.</p> 
<p>Your password won't change until you access the link above and create a new one.</p> 

Redirected to http://localhost:3000/users/sign_in 
Completed 302 Found in 6791ms (ActiveRecord: 17.0ms) 

回答