
Taming Large Rails Applications with Private ActiveRecord Models - vinnyglennon
https://kellysutton.com/2019/10/29/taming-large-rails-codebases-with-private-activerecord-models.html
======
cooljacob204
So this is really just hiding active record's methods in a model from the rest
of the App?

I don't really understand why this would be an advantage in a large app.

It's more explicit, but then you have to slow down and add all those wrappers
for active record stuff. I can also see it getting annoying/confusing if you
have a mix of normal models and these models in an app that you are not
familiar with.

When I think of and create a model I think of active record as part of that
public interface. And unless I want to restrict stuff I would want the default
to be exposed.

~~~
mosselman
I agree. It just makes it harder to reason about what is going on and what
will happen when you call methods.

A far better approach is to put related methods in concerns. When you do this
based on features, lets say a concern called "SyncToTrello" that contains all
the methods on lets say a "Task" model that are related to syncing to Trello.
So when I have to refactor or debug the sync, I just open up the concern and
look at the handful of methods that are related to just that. Rather than
having to scroll through a 500+ loc Task model.

Using concerns has been a great way to tackle growth in our Rails application.

------
prophetjohn
I think this is a wise approach for large Rails applications, but this just
looks like the Repository pattern to me, with ActiveRecord used as the db
interaction layer

------
briandilley
This is the DAO pattern, welcome to 1999 Ruby.

[https://www.baeldung.com/java-dao-pattern](https://www.baeldung.com/java-dao-
pattern)

~~~
bradstewart
It's not that Ruby has never heard of this pattern, the article even mentions
libraries that implement it (ROM, Sequel).

Rails made a choice to use the active record pattern instead. This article is
about adapting an existing application to a new pattern.

------
rawburt
I'm glad they mentioned ROM and Sequel. But of course, pragmatism beats
favoritism.

