3 ms·
Really interesting comment. I've started working on a Rails project. I don't have any professional experience with Rails in particular. Can you recommend any
by jwdunne 9y ago
Really interesting comment.
I've started working on a Rails project. I don't have any professional experience with Rails in particular.
Can you recommend any code bases I can read that meet these criteria?
- joshmn 9y agoMy personal favorite codebase is GitLab (thanks syste and team!) — they do a very fine job of pumping out Ruby while hanging out in the Rails ecosystem. https://gitlab.com/gitlab-org/gitlab-ce https://gitlab.com/gitlab-org/gitlab-ce — points of interest are in lib, as well as how they organize and call service objects from app/services.
- jwdunne 9y agoThis codebase is a pleasure to read. Thank you for the recommendation :)
- fyfy18 9y agoAs well as services, a couple of other folders you might want in app are for decorators and form objects. Form objects aren’t very common, but I’ve found it to be a really great patten for simplifying code. Strong params and ActiveRecord methods are fine for simple updates, but as soon as you get to something more complicated (e.g. what if you want validations to apply only for certain users?) it just becomes a mess - and you need to decide whether to have fat controllers or models. The idea is you put all the logic for parsing params and updating records into a form object. It keeps controllers and models skinny, and can easily be tested without having to go through a controller. The reform gem provides a few helpers that make them easy: https://github.com/trailblazer/reform/blob/master/README.md https://github.com/trailblazer/reform/blob/master/README.md
- faitswulff 9y agoAwesome, the form pattern is a useful one. My coworker and I were just talking about how frustrating it was to have validations coupled so tightly to the models and this would have helped a lot. Thanks!
- joshmn 9y agoI guess the idea is that you don't need to only use what Rails provides you, and you're free to bake in your own Ruby as you see fit. Rails is just Ruby, after all, and its modular enough at its core to be extensible for all sorts of applications. You just might have to do some digging to get your Ruby code Rails-friendly, such as using POROs alongside a form builder requires you to include ActiveModel::Naming
- cutler 9y agoYes, this is the BIG problem I see with Rails yet you don't hear many developers complaining about it. Django and Laravel seem to treat validation separately from the model and so does Node.js. Why is Rails so rigid about this? Although I generally like Rails this the single potential show-stopper for me.