Replies: 1 comment 1 reply
-
I maintain a modest codebase with over 100 policies. I typically do per-model policies. I use a plural namespace for nested resources, which typically line up with nested resource controllers. Sometimes policies are per-controller, and I use a similar naming convention, and explicitly use Lastly, personally, I'm not a fan of the singular namespaces, because it ends up nesting the policy under the |
Beta Was this translation helpful? Give feedback.
-
When I started using
action_policy
, I thought that "1 policy per controller" was the best way to organize my policies, eg:PostsController
=>PostPolicy
Admin::PostsController
=>Admin::PostPolicy
PostReportsController
=>API::PostPolicy
Admin::FeaturedPostsController
=>Admin::FeaturedPostPolicy
It is working for my projects, I'm working on other projects that use "1 policy per model/resource" and reuse the policy on multiple controllers, eg.:
I don't have any objections with the second approach, but I have the feeling it will become harder to maintain, while I know the first approach can be easier to have duplicated/outdated permission code without a proper.
How do you organize your policies and has it worked well??
Beta Was this translation helpful? Give feedback.
All reactions