私の誰Users
もがhas_many
と関係がありCharacter
ます。アプリケーションを使用する前に、まずメインとして1つのキャラクターを選択する必要があるためmembers
、メインキャラクターを選択するまで、コントローラーのshowメソッドにリダイレクトし続けます。
私のアプローチは機能しますが、たとえば誰かがメインキャラクターを選択する前にログアウトしたい場合、リダイレクトし続けるという問題があります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