Hacker News new | ask | show | jobs
by clairity 1650 days ago
i love rails, but i’d point out that business logic exists all over the place in a rails app, not just in the controllers. that’s because rails has no standard solution for compound requests (those involving many models and/or multiple actions) that go beyond the simple semantics of http verbs (which i totally appreciate for what they are). some might say that’s a design issue to be worked out depending on the situation, but sometimes, you just need to do lots of different stuff in a single request context.

rails doesn’t cope with that issue very well (some suggest a command or strategy pattern, others service objects, etc.), which is one of the only major criticisms i have with rails. node/npm dependency was another big criticism, but they’re fixing that with rails 7. =)

1 comments

I like creating a service/coordination layer between controllers and models to put the business logic. Controllers call the services or coordinators which can interact with models, kick off jobs, or call other services. Easy to test and change and keeps controller and model code more manageable. For smaller apps you can get away with shoving all your business logic in the models but that can become a little tough to manage as the logic becomes more complex.