Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将在很多模型中重用一些函数,在rails中,所以我认为必须有更好的方法来不重写代码或不在模型中加载帮助程序。
那么,实现这一目标的最佳方法是什么?
您可以将常用功能放在模块中
module CommonFunctions def common1 end def common2 end end
然后将它们包含在使用它们的模型中
class Comment include CommonFunctions end class Post include CommonFunctions end