ユーザーを管理するために使用している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 }
...しかし作業がありません。どんな助けもありがたい。
あなたはscope:organization_users、 - > {organization.users} 'を試しましたか? –
なぜ 'current_user.organization.users'を使用しないのですか? –