Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MincePie opened this issue Aug 29, 2016 · 0 comments
Open

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

MincePie opened this issue Aug 29, 2016 · 0 comments

Comments

@MincePie
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant