嗨,我正在尝试提示用户密码重置...我在Rails应用程序中使用Devise,但是该逻辑适用于检查过期的密码,但是当我尝试将用户重定向到devise根目录时(edit_password_path等)它们被重定向到root_path?我如何禁用此默认行为,因为除设计特定的根目录外,它们可以重定向到其他任何地方...
这是我的代码
def is_password_expired?
if current_user.password_updated_at.present? || !current_user.password_updated_at.to_datetime.between?(
Time.now.to_datetime - 3.months, Time.now.to_datetime)
redirect_to edit_user_password_path
elsif !current_user.password_changed_at.to_datetime.between?(
Time.now.to_datetime - 3.months, Time.now.to_datetime)
redirect_to edit_user_password_path
else
return true
end
end
所以我尝试创建一个after_sign_in_path(resource)方法,这将我带到了edit_user_path端点,但是浏览器只是在说
This page isn’t working
localhost redirected you too many times.
config.rb
devise_scope :user do
get 'login' => 'users/sessions#login'
get 'password_submitted' => 'users/passwords#submitted'
get 'confirmations/submitted' => 'users/confirmations#submitted'
get 'users/sign_up_as_lender' => 'users/registrations#sign_up_as_lender'
get 'users/registration/investor' => 'users/registrations#investor'
get 'users/registration/borrower' => 'users/registrations#borrower'
get 'users' => "users/registrations#new"
get 'users/password' => 'users/passwords#new'
put 'users/passwords/change' => 'users/passwords#update_password'
put 'users/passwords/change' => 'users/passwords#update_expired_password'
end
resources :passwords, only: [:new, :edit, :submitted, :create, :update]
get 'login', to: 'sessions#new'
get 'sessions/create', to: 'sessions#new'
post 'sessions/create', to: 'sessions#create'
delete 'signout', to: 'sessions#destroy'
get 'password-submitted' => 'passwords#submitted'
end