3 ms·
> Taking a peak at my usual interface stack includes commands, components, decorators, forms, inputs, queries, presenters, serializers, and services. This is in
by ysavir 3y ago
> Taking a peak at my usual interface stack includes commands, components, decorators, forms, inputs, queries, presenters, serializers, and services. This is in addition to the default controllers, helpers, mailers, models, views.
Would love to hear a short bit on what each of these does in your Rails codebases! I'm familiar with decorators, queries, presenters, serializers, services, but commands, components, forms, and inputs are new to me. Would be great to see what I'm missing out on.
- joshmn 3y agoSure, here's a brief tour: Commands — I usually will ship with Rectify https://github.com/andypike/rectify https://github.com/andypike/rectify. It's a great layer for my controller to handle request contexts. You might think this is a glorified service object but I'm not a fan of service objects unless they do just one thing (and are allowed to loudly fail). Components — https://viewcomponent.org/ https://viewcomponent.org/ I'm not incredibly sold on them but they do clean things up. Forms — Rectify has this shipped but it uses Virtus which is quite old and hasn't been touched in many years. Shipping my own similar is usually something like https://gist.github.com/joshmn/39eb6f302650e09743387710591abb2d https://gist.github.com/joshmn/39eb6f302650e09743387710591ab.... Not all of my form attributes will map directly to a model, but I want my form helpers to actually help me so I need some sort of object that _can_. Inputs — I'll extend SimpleForm inputs (something I can't live without) to DRY up my forms. All together, this is typically something like this (the form and command pattern, at least): https://gist.github.com/joshmn/65cfbccc6c64abe6d463ba9708b00ca6 https://gist.github.com/joshmn/65cfbccc6c64abe6d463ba9708b00... (not tested) There's usually also an `admin` directory since I also usually ship with ActiveAdmin or Trestle. I've fallen in love with the latter after making it behave more like ActiveAdmin. When I need to drop out of its usual constructs I'll just write a custom controller, but for the majority of administrative stuff I can get 95% of the way there with the DSL of either/or, freeing up time for domain-specific problem solving.