-
Notifications
You must be signed in to change notification settings - Fork 637
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
Re-use policy instance when passing explicit policy class? #740
Comments
Hi @mattzollinhofer! I'd be interested in hearing your reaction to the following idea: #774 |
I believe you should be able to manually instantiate the policy this way:
Hope this helps for now. |
Question on this particular issue, are you looking to specifically get the same instance back, or just the same policy lookup behaviour? For the latter, the above comment seems sufficient to me: #740 (comment) |
@Burgestrand: I'm a few years removed from this project at this point so my memory is failing on this front. I believe the point was that As I said, I'm far enough removed that I'm struggling to recall the specific details ... but my recollection is that from a user's perspective, the idea of having the controller declare/provide a custom policy that would be used for both the controller (via I see you merged a PR that's starting to move in this direction, but are still thinking about some of these details. Great work! I'm really impressed at how you've been able to keep up with this!!! I've needed to change projects into a Java/React space, but this very long 😄 conversation we've had over the years gives me a bit of inspiration that getting back to a rails project would be wonderful!!! Love the people in this community! |
Basic Issue
If I use a custom policy for authorization (ex:
authorize @post, policy_class: SpecialPostPolicy
) in my controller how do I usepolicy(@post)
to get the same policy in my view? Here's an example.Simple Use Case
Controller:
View:
Additional Commentary
I believe that in a previous version of Pundit the
authorize
call would call thepolicy
method that was mixed into the controller it was working in the context of. But when authorization was extracted, I think that link was broken. We'd used that "seam" to be able to overridedef policy
in our controller which allowed both theauthorize
call and the view to use the same policy. It's unclear to me how to use the same custom policy now. I believe this comment is referring to a related idea.The text was updated successfully, but these errors were encountered: