Using Presenters

Learn about Ruby presenters, their helper methods, performance, and how to write tests using presenters.

View testing presenters

Testing helpers is handy, but if we have a lot of logic in the helpers, we recommend moving the logic into presenter objects. This is especially true if we have a series of helpers that take the same argument.

Ruby presenters

There’s nothing complicated about using presenters in Rails. We can use them using Ruby’s SimpleDelegator class. If we want a little more structure, we can use the draper gem.

We can convert the project helper to a project presenter. This version of the code uses SimpleDelegator and includes a method for converting a list of projects into a list of presenters. In a break from convention, we’ll show the code first:

Get hands-on with 1400+ tech skills courses.