我的application_controller.rb中有一个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)
答案 0 :(得分:0)
通过将stored_locations_for(resource)
设置为nil,可以走得更远,然后为每个操作设置不同的重定向,例如:after_sign_up_path(resource)
,after_sign_in_path(resource)
,等等。
#条路.rb
devise_for :users, :controllers => {:registrations => "registrations"}
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
dashboard_path
end
end