【发布时间】:2016-09-06 01:21:39
【问题描述】:
我想使用 after_sign_in_path_for 和 after_inactive_sign_up_path_for 方法将用户重定向到某个特定页面,我会将这两个方法和 before_action :authenticate_user! 全部放在应用程序控制器中,但是,当 before_action 方法运行时调用所有操作,这会将我的应用程序重定向到错误的路线。我应该使用before_action :authenticate_user!, except: [:after_sign_in_path_for, :after_inactive_sign_up_path_for] 跳过这两种方法的身份验证吗?
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate!
def after_sign_in_path_for(user)
if user && user.is_a?(Vendor)
return edit_vendor_registration_path
elsif user && user.is_a?(Customer)
return dashboard_path
end
end
def after_sign_out_path_for(user)
if user && user.is_a?(Vendor)
return root_path
elsif user && user.is_a?(Customer)
return root_path
end
end
def authenticate!
if @current_user == current_customer
:authenticate_customer!
elsif @current_user == current_vendor
:authenticate_vendor!
end
end
end
我遇到了这个错误Filter chain halted as :require_no_authentication rendered or redirected,我相信程序以某种方式创建了一个无限循环,不断重定向到dashboard_path。
【问题讨论】:
-
也就是说,before_action方法应该不会影响这两个方法吧?但是,在使用前操作和应用程序控制器中的两种方法时,我会重定向到错误的路由
标签: ruby-on-rails ruby model-view-controller devise before-filter