News for hackers. Stuff that matters.
Re:From Rails to Clojure, Then to Java, Then Back to Rails by joshmn on Wednesday March 21, 2018 @02:02PM (#16640735)
The articles touches on this but just to reiterate because it's worth saying: The most important thing about Rails is knowing how the internals work and maintaining a clean code architecture. Too many times have I seen a mess in Rails because developers only use the APIs and DSLs given to them.

The best Rails codebases are the ones who have ample "vanilla" Ruby and just happen to use Rails alongside said Ruby.

Re:From Rails to Clojure, Then to Java, Then Back to Rails by jwdunne on Wednesday March 21, 2018 @03:08PM (#16641314)
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?

Re:From Rails to Clojure, Then to Java, Then Back to Rails by joshmn on Wednesday March 21, 2018 @03:32PM (#16641515)
My 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 — points of interest are in lib, as well as how they organize and call service objects from app/services.
Re:From Rails to Clojure, Then to Java, Then Back to Rails by fyfy18 on Wednesday March 21, 2018 @05:36PM (#16642646)
As 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

Re:From Rails to Clojure, Then to Java, Then Back to Rails by faitswulff on Wednesday March 21, 2018 @09:23PM (#16644587)
Awesome, 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!
Re:From Rails to Clojure, Then to Java, Then Back to Rails by joshmn on Wednesday March 21, 2018 @11:41PM (#16645511)
I 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
Re:From Rails to Clojure, Then to Java, Then Back to Rails by cutler on Thursday March 22, 2018 @01:05AM (#16645916)
Yes, 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.
Re:From Rails to Clojure, Then to Java, Then Back to Rails by jwdunne on Wednesday March 21, 2018 @04:07PM (#16641850)
This codebase is a pleasure to read. Thank you for the recommendation :)