RailsApps / rails-devise-pundit

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.
http://railsapps.github.io/rails-devise-pundit/
483 stars 156 forks source link

Why do you use attr_reader when you also use @ in action methods? #32

Open MincePie opened 8 years ago

MincePie commented 8 years ago

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.