The simplest solution would be to create a module under lib and mix this into the models that need it, for instance, in lib/fooable.rb:module Fooable def do_foo endend然后在您的各种模型中:And then in your various models:class MyModel < ActiveRecord::Base include Fooableend不需要 fooable.rb,只要使用正确的约定命名,Rails 自动加载机制就会为您找到它.No need to require fooable.rb, the Rails autoloading mechanism will find it for you as long as it's named using correct conventions. 这篇关于模型“实用程序"放在哪里Ruby on Rails 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 17:59