Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 自动加载路径更改命名约定_Ruby On Rails_Ruby_Ruby On Rails 3_Gem - Fatal编程技术网

Ruby on 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

我对Rails用于加载其
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)