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

Guest users (no current_user) #89

Closed
oliverbarnes opened this issue Jan 8, 2014 · 3 comments
Closed

Guest users (no current_user) #89

oliverbarnes opened this issue Jan 8, 2014 · 3 comments

Comments

@oliverbarnes
Copy link

What's the recommended way to scope collections on a controller when a user isn't logged in, and a current_user isn't available?

As in a public listing available to non-registered users, and a private one for logged-in ones.

@tbuehlmann
Copy link

Well, current_user could return nil then, which you could check in the actual Policy. Depending on the outcome of this you act.

@oliverbarnes
Copy link
Author

I see, policy_scope() won't barf by not having current_user set then... should have checked for that :) thanks

@dmitrypol
Copy link

dmitrypol commented Aug 16, 2016

What about doing this in application_controller?

include Pundit
def pundit_user
  current_user ||= User.new # guest user
end

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

3 participants