开发者

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 i开发者_StackOverflow社区t in lib?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜