Do Basecamp/Hey use ViewComponents?

I think building one object that contains every value that goes into a view is a useful practice, regardless whether you use templates or serialize that object straight into json. It’s useful because when you call directly into models from various templates and partials, you make your view dependencies unmanageable, and scattered across many files. It’s very hard to collect them back and understand what’s needed to render a view. This makes web responses harder to optimize and cache. Instead, if you build a single object first, and then use only that object in your template, you will be able to have your entire response dependencies in one place, which makes it easier to fully optimize sql and other data acquisition necessary to render a response.

That said, I think ViewComponent adds the (imo) unnecessary requirement of having to write templates in ruby. A plain Ruby object combined with standard Rails templates works perfectly fine for this. I recommend portrayal (excuse the plug :slight_smile: ) for lightweight view-objects.

1 Like