rubocop/rails-style-guide

Clarify recommendation to use a decorator or presenter

asavageiv opened this issue · 2 comments

The guide recommends using a decorator or presenter for complex formatting in views. What exactly is meant by this? Can you link a good resource or example? Or have a "---BAD---" "---GOOD---" example in the guide to show what is meant and why it's good advice?

pirj commented

I guess it means that:

# bad
= t user.role
= l user.time
= h.first_name(user.full_name)

Since those definitions could be abstracted out to a decorator and re-used across views, it makes sense to recommend doing so to avoid duplication of error-prone logic, test isolation etc.
The examples above don't even fall into "complex" in my book, but I would prefer to see such formatting separate from the view.

pirj commented

I would disagree with my past self.
Anyway, it surely makes sense to clarify the case when it's beneficial to extract the formatting logic into a helper/decorator.
But keeping this ticket open just to indicate there's a deficiency doesn't.