开发者

What's a good place for modules in a rails project

开发者 https://www.devze.com 2022-12-19 04:10 出处:网络
I\'m adding some non-trivial functionality in my rails application and it needs to be in a module and not one of the auto generated models.I\'d like a few suggestions on where the file containing the

I'm adding some non-trivial functionality in my rails application and it needs to be in a module and not one of the auto generated models. I'd like a few suggestions on where the file containing the module should go (currently I've added a 'code' directory on the same level as 'models' and 'views' - but I don't know that that's a strong开发者_StackOverflow社区 choice).


Most people add this type of code in lib


If it's related to the controller/view layer, consider putting the functionality in a helper. If not, lib is a good general storage directory for util classes and the like. If at all possible, think about making extra code like this a plugin, as it helps keep the codebase clean and reusable functionality available to other projects.

0

精彩评论

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

关注公众号