开发者

Where to place business-logic classes

开发者 https://www.devze.com 2023-02-24 02:58 出处:网络
For example, I have a class which collect data from web-sites and开发者_如何学运维 return object collections.This data doesn\'t store in the database so it is not model.This class is used by many cont

For example, I have a class which collect data from web-sites and开发者_如何学运维 return object collections. This data doesn't store in the database so it is not model. This class is used by many controllers so it is not controller.

Where can I place such files?


Should go into lib folder! As Modules perhaps!


I would put them in app/models. Then you don't have to deal with the autoload path or with require vs. require_dependency.

Just because a class isn't persisted to your database doesn't mean it isn't part of your data model. Putting them in lib suggests they're some sort of utility class that doesn't have much to do with your app.

Rails confuses model and persistence. I think it's fine to have some of your business logic along with your persistent entities, but there's no reason why you can't have model logic outside of your ActiveRecord objects.


I usually place those classes in the lib directory. and than just require them.


Its a value object and should remain same for whole site, and your controller or other components should use its refernce from model, class refernce should be in model and class it self can be put with value object

0

精彩评论

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