Reputation: 6121
I'm working on a project that involves seven different kinds of users. These users each have a very similar-looking dashboard.
They're almost exactly the same for each user, but do differ slightly:
I'd love to make the code more DRY but how do I approach this problem if partials will complicate the layout rather than simplify it, in this case?
My initial idea was to display ALL the elements, but hide/restrict them with if
statements, making for one, but very logic-heavy view.
More broadly speaking, if the UI changes significantly based on the privilege level of the user viewing it, what's the accepted Rails pattern for keeping things organized?
Upvotes: 0
Views: 110
Reputation: 52357
I think Pundit will be the perfect fit for you if DRY and OO are the concerns :). It is really super object-oriented and clean approach.
Essentially, you'll move all the (often complicated) authorization logic to policies, and you're views will look like this (from docs):
<% if policy(@post).update? %>
<%= link_to "Edit post", edit_post_path(@post) %>
<% end %>
Upvotes: 1