Hacker News new | past | comments | ask | show | jobs | submit login

Can you share a link about what you mean by this?

I went searching but came up pretty empty ... do you literally mean adding an "app/services" directory, is that all? Where you put classes related to external dependencies that aren't ActiveRecord?




I don't agree with the pattern discussed here and actually like smart models (I want to tell my model "do the thing", not write and babysit a bureaucratic coordinator service. But, since you asked, it's common in other frameworks like Spring to have a "service" layer that sits between your controller and model layers. The service layer has the logic, and the models are just storage.


That's common in Rails too. Except I don't think it's necessary to make it a go-between.

Where controllers have simple interactions with models (which represent database structures, and may have logic in them) you let the controller have direct access to the model.

Models can grow to be too complex, this is where having a concept of named "Concerns" can come in handy, even if you won't use them in another model, it can lift some complexity out of your model and put it into a logical group.

Services, in my view, are akin to models. Some of them may use models behind the scenes. More of them actually represent an external service, which might be an external database that lives behind a web service, an API. Or it might be an LDAP service. (Or it might be a command pattern)

I agree with smart models, if the complexity does belong to the model, then why not let it live there. It sounds like the service layer you're describing is a needless ceremony for "managing complexity" – I'll bet it was a concept that was introduced to your group by an architect.


Don't you mind having 5000+ LOC model? Methods being redefined because the class is huge and the developer didn't notice the existing method?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: