Ruby on rails 自动加载路径更改命名约定
我对Rails用于加载其Ruby on rails 自动加载路径更改命名约定,ruby-on-rails,ruby,ruby-on-rails-3,gem,Ruby On Rails,Ruby,Ruby On Rails 3,Gem,我对Rails用于加载其config.autoload\u路径文件的命名约定有问题 我正在构建一个使用一些gem的应用程序 应用程序应该扩展这组gem,如果gem中定义了模型用户,那么如果应用程序想要扩展该模型,则必须创建一个名为“app/models/_User.rb”的文件,并在该文件中编写如下内容: # Extending gems user model in the application level class User < ActiveRecord::Base def ne
config.autoload\u路径文件的命名约定有问题
我正在构建一个使用一些gem的应用程序
应用程序应该扩展这组gem,如果gem中定义了模型用户
,那么如果应用程序想要扩展该模型,则必须创建一个名为“app/models/_User.rb”
的文件,并在该文件中编写如下内容:
# Extending gems user model in the application level
class User < ActiveRecord::Base
def new_method_that_make_sense_for_my_app
#supercode here... bla bla
end
end
Rails不会在每次请求时自动加载此文件,因为自动加载路径元素依赖于文件的名称等同于该文件中定义的类的名称的约定
因此,继续:文件名“\u user.rb”
中的下划线将一切搞乱
有没有一种方法可以配置Rails,这样我就可以告诉它也搜索以下划线开头,后跟类名的文件
谢谢
config.autoload_paths += %W(#{config.root}/app/models/_user.rb)