在Rails项目中保留自定义Exception定义的常规位置是什么? [英] What is a conventional place to keep custom Exception definitions in a rails project?
本文介绍了在Rails项目中保留自定义Exception定义的常规位置是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在创建自己的自定义例外时,例如
When making one's own custom exceptions like
class ThingExploded < StandardError; end
class ThingIsMissing < StandardError; end
哪里有保存这些东西的好地方?我正在考虑 lib / exceptions.rb …,并且还在考虑是否更合适地以某种方式使它们更接近使用它们的代码。
Where is a good place to keep these? I was considering lib/exceptions.rb… and also pondering if it would be more appropriate to somehow put them closer to the code that uses them.
推荐答案
我要使用 app / models / model_name / exceptions.rb
,将它们保留在模块中。
I'm going with app/models/model_name/exceptions.rb
, keeping them inside the module.
这篇关于在Rails项目中保留自定义Exception定义的常规位置是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文