사용자 관리에 사용하는 dashboard_controller가 있습니다. 여기 컨트롤러가 있습니다 :이 방법을 대체 할 적절한 범위는 무엇입니까?
class DashboardController < ApplicationController
before_action :authenticate_user!
def index
if current_user.admin?
@users = current_user.get_organization_users
else
flash[:notice] = "Unauthorized Page View"
redirect_to(tasks_url)
end
end
참고 저는 @users = current_user.get_organization_users
입니다. 다음은 내 사용자 모델의 get_organization_users 메소드입니다.
def get_organization_users
self.organization.users
end
어떻게 이것을 범위로 바꿀 수 있습니까? 나는 시도했다 ...
scope :organization_users, -> { self.organization.users }
... 그러나 worky. 어떤 도움을 주셔서 감사합니다.
scope : organization_users, -> {organization.users}'해 보셨습니까? –
왜'current_user.organization.users'를 사용하지 않을까요? –