Blankman
Blankman

Reputation: 267290

Where to put business logic that spans multiple models?

I have a situation where I can't figure out where to place this business logic.

In rails the best practise is to have fat models and thin controllers.

Now I have a situation where I am interacting (updating mostly) 3-4 model records.

Where should I put this logic? Should I make a 'service' type class and put it in lib?

Upvotes: 1

Views: 488

Answers (2)

Nick
Nick

Reputation: 2413

Sometimes it might be worth just creating another class in the models folder that backs to AR based models. A 'model' doesn't have to be limited to a DB table.

Upvotes: 0

apneadiving
apneadiving

Reputation: 115541

Trying to get something to backup the evidence, I found this, chapter 1.2.3.

lib/ Library modules

Which is definitely the most logical place to use for trans-model code.

It's basically the place where we put most of our code when writing acts_as_whatever gems.

Upvotes: 3

Related Questions