Re:10 Most Common Rails Mistakes
by jstin on Tuesday June 03, 2014 @12:32PM
(#7841182)
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.
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.