What is the Rails Presenters folder for?

The Presenters folder is where your Presenter code would go. I know, obvious, I'll explain.

The way I think of Presenters and Decorators is as an abstraction of a Model in order to massage the data attributes before they are given to view.

If you are familiar with helpers, well, Presenters are kind of like helpers in the sense that they are getting some data ready for the view, except helpers usually serve as utility methods for said views, while presenters are more about presenting the actual attributes.

This link explains the difference very well: https://awead.github.io/2016/03/08/presenters/

hope that helps.


Presenters de-clutter your views

When people mention presenters in a rails context (as opposed to discussions of Model-View-Presenter, MVC, MVVM discussions etc) they are referring to a situation where things look really complex in your views: there are plenty of if statements everywhere, and it's difficult to read through it all.

Or to adopt an everyday analogy: imagine you have a really messy house, with stuff piled up everywhere - so that it's difficult to walk through. You can think of a presenter as a large garage where you can neatly organise everything. This makes it much easier to walk through your house, and you still have all the utensils that you need.

Getting back to the rails context: Presenters allow you to remove all that complex logic somewhere else: into the Presenter's folder, so that when you read your views, it will be a lot easier to understand from a higher level. The clutter isn't there, the complexity isn't there: that has been transferred somewhere else. If you want more detail, you will have to go to the relevant folder. The logic need not be contained in a folder called "Presenters" but it can be put there by convention.


presenters is a design pattern commonly reffered to as Model View Presenter(MVP)

This is a derivation of the Model View Controller pattern and is used for creating user interfaces.

It's useful for the Separation of Concerns for making code more DRY.

Here's how Wikipedia describes it

model - interface defining the data to be displayed or otherwise acted upon in the user interface.

presenter - acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

view - a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter

Presenters in Ruby on Rails

Presenters are simple classes that sit between the model and the view and provide a nice, DRY object oriented way of working with complex display logic.

In Rails, the convention is for them to be located in the app/presenters folder

Here is a userful article that explains the pattern and its use in Ruby on Rails.

https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/