2010-02-12 3 views
0

단일 사용자 분류에 대해 before_filter를 사용하는 방법에 대해 잘 설명되어 있으므로 여러 사용자 유형에 대한 작업 수준 보호를 얻는 데 문제가 있습니다. 설명해 드리죠 : 나는 이런 식으로 뭔가있어Authlogic 및 STI를 사용하여 활동 레벨 보호를 얻는 방법은 무엇입니까?

을 ...

class ApplicationController < ActionController::Base 
    class << self 
    attr_accessor :standard_actions 
    end 
    @standard_actions = [:index, :show, :new, :edit, :create, :update, :destroy] 

    def require_guardian 
    unless current_user and current_user.is_a?(Guardian) 
     store_location 
     redirect_to home_url 
     return false 
    end 
    end 

    def require_admin 
    unless current_user and current_user.is_a?(Administrator) 
     store_location 
     redirect_to register_url 
     return false 
    end 
    end 
end 

그리고 난 단지 표준 관리자의 작업을하지만 다른 모든 행동은 보호자를 필요로한다을 허용 할 GuardiansController에서

. 그래서 이것을 시도 ...

결국 재귀 적 리다이렉션이 끝납니다. 더 좋은 방법이있을거야?

답변

0

좋아, 이것은주의 깊게보고 누락 된 또 다른 경우입니다. 실수로 재귀 적으로 사용자를 리디렉션하는 경로를 설정했습니다. 위의 해결 방법은 올바르게 경로를 설정할 때 잘 작동합니다.

def require_guardian 
    unless current_user and current_user.is_a?(Guardian) 
    store_location 
    # this route (home_url) sent the user to another controller which ran a before_filter sending them back here again. 
    # redirect_to home_url 
    # So I changed it to a neutral route and it works great! 
    redirect_to register_url 
    return false 
    end 
end