I saw in the user policy example you have, you use:
class UserPolicy
attr_reader :current_user, :model
def initialize(current_user, model)
@current_user = current_user
@user = model
end
def index?
@current_user.admin?
end
I thought the point of attr_reader was to set access to the local variable. If that's the case, why do you use '@' in the action methods? Shouldn't your notation be 'current_user.admin? in the action methods?
I'm trying to learn how to write scopes and getting very stuck with the examples I can find to this point. I think my struggles have something to do with the notation. I'd love to know why you use this format. It might help me understand what's going wrong for me.
I saw in the user policy example you have, you use:
class UserPolicy attr_reader :current_user, :model
def initialize(current_user, model) @current_user = current_user @user = model end
def index? @current_user.admin? end
I thought the point of attr_reader was to set access to the local variable. If that's the case, why do you use '@' in the action methods? Shouldn't your notation be 'current_user.admin? in the action methods?
I'm trying to learn how to write scopes and getting very stuck with the examples I can find to this point. I think my struggles have something to do with the notation. I'd love to know why you use this format. It might help me understand what's going wrong for me.