【发布时间】:2016-05-10 02:31:54
【问题描述】:
我有两个模型供应商和客户,在应用程序控制器中我为每个模型定义了after_sign_in_path_for 方法,但是在为客户注册并确认后,当我登录时,我重定向到供应商登录页面而不是@987654322 @。出现这个问题是因为我将两个模型的方法都放在了应用程序控制器中,我是否应该将每个方法都放在相应的会话控制器中?
我认为错误重定向的原因是无限循环。下面的应用程序控制器代码有什么问题吗? 我只写了这个应用程序控制器,其他的都是内置的。
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?(Customer)
customer_dashboard_path
elsif user && user.is_a?(Vendor)
vendor_dashboard_path
end
end
def after_sign_out_path_for(user)
if user && user.is_a?(Customer)
root_path
elsif user && user.is_a?(Vendor)
root_path
end
end
def after_inactive_sign_up_path_for(user)
if user && user.is_a?(Customer)
root_path
elsif user && user.is_a?(Vendor)
root_path
end
end
def authenticate!
if @current_user == current_customer
:authenticate_customer!
elsif @current_user == current_vendor
:authenticate_vendor!
end
end
end
【问题讨论】:
标签: ruby-on-rails ruby redirect model-view-controller devise