![](/img/trans.png)
[英]Devise - redirect to the user clicked after sign in, if the user is not signed in
[英]Why gem devise redirect to sign up path after user signed in?
我的after_sign_in_path_for
中有一個after_sign_in_path_for
方法。用戶after_sign_in_path_for
,該方法成功調用(我檢查了加薪)。 不幸的是,成功登錄后,用戶總是重定向到new_user_session
(/ users / new)而不是我的dashboard_path
(/ dashboard)。 我希望用戶登錄后重定向到儀表板路徑。您是否有什么線索可以替代我重定向到dashboard_path的方法?
這是我的代碼
application_controller.rb
class ApplicationController < ActionController::Base
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def after_sign_in_path_for(resource)
dashboard_path
end
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:first_name, :email, :password, :password_confirmation, :remember_me) }
end
end
日志
Started POST "/users/sign_in" for 127.0.0.1 at 2018-09-17 14:48:22 +0200
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"1vtsPGq6tRhJAjUn+hwoMIwfeDjOEMzpEejQVQfT9r/4B1aMv7B727E71F3qLoobyUN5mQkWLzbo/RNxHWZQJQ==", "user"=>{"email"=>"tdesfrancs@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["email", "tdesfrancs@gmail.com"], ["LIMIT", 1]]
(0.2ms) BEGIN
(0.1ms) ROLLBACK
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (1.1ms)
Rendered devise/sessions/new.html.erb within layouts/application (8.7ms)
Rendered shared/_flashes.html.erb (0.4ms)
Completed 200 OK in 303ms (Views: 120.7ms | ActiveRecord: 1.5ms)
您可以通過將stored_locations_for(resource)
設置為nil來走得更遠,然后為每個操作設置不同的重定向,例如: after_sign_up_path(resource)
, after_sign_in_path(resource)
等。
#routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
dashboard_path
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.