Hacker News new | ask | show | jobs
by charlysisto 3685 days ago
A simple formula to take a lot of AR's bloat away is to use it mainly as a read library (AR's great for generating complex queries in a simple & readable manner).

For write operations (aka user interaction) I use a combination of solnic gem (Virtus) with ActiveModel that way I remove a s*t load of responsibilities from AR and the controller : - params management (and strong params) - validations - nested associations - callbacks - And all the context management (like user vs admin...)

That way I only mildly part from the rails way and yet have a good separation of concern. Actually ActiveModel is used by ActiveRecord so having a form object relying on it is still very much rails compliant. The refactoring is minor (no hexagonal stuff) and the level of indirection very low.