Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
使require_依赖项在Rails项目中的任何Ruby文件中工作_Ruby_Ruby On Rails 4 - Fatal编程技术网

使require_依赖项在Rails项目中的任何Ruby文件中工作

使require_依赖项在Rails项目中的任何Ruby文件中工作,ruby,ruby-on-rails-4,Ruby,Ruby On Rails 4,我希望在Rails应用程序中使用require_依赖项,而不使用: require 'active_support/dependencies' 该解决方案是由Q&A提出的 我已经使用名为TestRails的版本4.1.5创建了一个新的Rails应用程序。在lib文件夹中,我添加了一个名为test_rails.rb的新Ruby文件,其中我放置了: require_dependency "plugin/instance" # << fails here module TestRai

我希望在Rails应用程序中使用require_依赖项,而不使用:

require 'active_support/dependencies'
该解决方案是由Q&A提出的

我已经使用名为TestRails的版本4.1.5创建了一个新的Rails应用程序。在lib文件夹中,我添加了一个名为test_rails.rb的新Ruby文件,其中我放置了:

require_dependency "plugin/instance"  # << fails here

module TestRails
  def self.doSomethingAwesome
      # some real work here
  end
end
加载上面的lib文件

但是,当我尝试运行应用程序时,会出现一个错误:

TestRails/lib/test_rails.rb:1:in `<top (required)>': 
undefined method `require_dependency' for main:Object (NoMethodError)

如果我明确添加require‘active_support/depdencies’,require_依赖项行将起作用。我一直在浏览GitHub存储库中的Distance,他们的代码使用需要依赖性,而没有我使用过的明确要求,但我似乎无法发现他们是如何做到的。

Distance在Gemfile中有这样一行:

gem 'seed-fu', '~> 2.3.5'
seed fu需要activerecord,而activerecord又需要活动的支持/依赖项。看

gem 'seed-fu', '~> 2.3.5'