Hacker News new | ask | show | jobs
by jstin 4406 days ago
I've been using the CanCan(Can) gem to handle all permissions logic, both in controllers and views. It abstracts all user state logic to a single file https://github.com/CanCanCommunity/cancancan

I find this pattern to be the most manageable especially in large projects.

But I agree with your point. "if current_user" is miles better than "if current_user.name != 'Guest'".

Edited to add: As far as this articles use of current_user.name being guest, it makes sense to use a presenter to display the data in the view. Conditionally displaying a user name or 'Guest' in a view is kinda gross. Again I'll suggest a gem for this pattern https://github.com/drapergem/draper

All objects coming into the view should be wrapped, especially and ActiveRecord objects.

1 comments

Draper is great in general for keeping display logic away from controllers and views (as per mistakes 1 and 2).