DEV Community

Discussion on: Business logic in Rails with operators

jaredcwhite profile image
Jared White • Edited on

You:

Business logic should never go inside a model.

Rails:

The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.

Source:
github.com/rails/rails/blob/main/R...

I think I shall trust what Rails says models are in Rails. 🙂 If you want to extend your own architecture beyond the "Rails way", that's certainly your prerogative, but for any folks out there creating POROs in app/models or even simply using ActiveRecord objects to encapsulate business logic, you are doing exactly what Rails says you should do. I rest my case.