3 ms·
I've found a happy balance developing with rails by adding two strategies: 1) Use presenters for display-only logic to keep controllers concerned with managing
by nwienert 13y ago
I've found a happy balance developing with rails by adding two strategies:
1) Use presenters for display-only logic to keep controllers concerned with managing requests only.
2) Using service object / custom classes in /lib for actions on models as well as abstracting any common related functionality. Creators, Updaters, Processors, Orchestrators, etc. Keep your models only concerned with data and not data transformation, and your controllers from doing it as well.
- tomblomfield 13y agoYes, definitely. One of the future posts (coming soon!) will be on Presenters / Decorators. I would argue these custom classes should still live in /app, rather than /lib, but I may be wrong.
- jhund 13y agoI have documented my strategy for moving from a simple MVP to a maintainable and complex Rails app. Basically I look at factors like how many objects are affected by an operation, and how complex the additional processing is. TL;DR: Use Rails magic when possible, and Object Oriented best practices when necessary. I created a flowchart that illustrates this strategy: http://rails-recipes.clearcove.ca/pages/how_to_change_objects.html http://rails-recipes.clearcove.ca/pages/how_to_change_object...