In order to review blog posts, admins can see additional information.
- if current_user.admin?
// html with details of the blog post
- it works
- it's clear
... but
- admins can see details
- reviewers can see details
- reviewers are admins
VS
- admins can see details
- reviewers can see details
- reviewers are admins
!=
if is the only criteria for all actions in the code, we can't track the intentions.
It's introducing hidden costs in understanding and maintenance.
current_user.admin?
Authorization gems are dedicated to this task.
Or you can create meaningful methods
class User
def can_review_posts?
admin?
end
end
- if current_user.can_review_posts?
// html with details of the blog post
Most of the time, feature requests themselves confuse intention and implementation.
Think twice before coding, and make business logic appear in your code.