我的每一个人Users
都has_many
与Character
。现在,在他们可以使用应用程序之前,我需要他们首先选择一个角色作为他们的主要角色,因此我想继续将他们重定向到members
控制器显示方法,直到他们选择主要角色。
我的方法有效,但是当有人想在选择主要角色之前注销时会出现问题,它会不断将他们重定向到member_path
. 如何将devise
控制器添加到此规则和整个members
控制器的例外中。
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :check_for_main
skip_before_filter :check_for_main, :only => [:members => :show, :users => :sign_out]
# Check if user has a main character selected
private
def check_for_main
# Check signed in user
if user_signed_in?
# Check associated characters if any are set as main
redirect_to member_path(current_user.id), :alert => "Please select your main character."
unless current_user.characters.any?(&:main)
end
end
end
end