简体   繁体   English

发送重置密码指令后重定向

[英]Redirect after sending reset password instruction devise

I know, I can create PasswordsController on my apps following this wiki How To: Redirect URL after sending reset password instructions 我知道,我可以在我的应用程序之后根据此wiki创建PasswordsController 如何:在发送重置密码指令后重定向URL

My Questions is : 我的问题是:

Why I can't move after_sending_reset_password_instructions_path_for(resource_name) method to ApplicationController looks like : 为什么我无法将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

Still redirect to default path localhost:3000/users/sign_in 仍然重定向到默认路径localhost:3000/users/sign_in

I'm sure, I have user_login_path in my routes.rb 我确定,我的routes.rb中有user_login_path

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

And this stack trace when I send instruction reset password : 当我发送指令重置密码时,这个堆栈跟踪:

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"=>"myemail@gmail.com"}, "commit"=>"Send me reset password instructions"}
  ←[1m←[35mUser Load (3.0ms)←[0m  SELECT  "users".* FROM "users"  WHERE "users"."email" = 'myemail@
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  myemail@gmail.com (5611.3ms)
Date: Mon, 29 Sep 2014 16:32:13 +0700
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: myemaik@gmail.com
Message-ID: <5429271df3e90_1534f9a9b0166f0@ASUS-PC.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello myemail@gmail.com!</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)

because the sign_in and sign_out methods are public and the method after_sending_reset_password_instructions_path_for is protected. 因为sign_in和sign_out方法是公共的,并且方法after_sending_reset_password_instructions_path_for受到保护。 You need to create a controller which inherits from Devise::PasswordController. 您需要创建一个继承自Devise :: PasswordController的控制器。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM