Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 捆绑包安装从不正确的目录运行_Ruby_Gem_Rvm_Bundler_Thor - Fatal编程技术网

Ruby 捆绑包安装从不正确的目录运行

Ruby 捆绑包安装从不正确的目录运行,ruby,gem,rvm,bundler,thor,Ruby,Gem,Rvm,Bundler,Thor,我正在为一些内部项目构建一个简单的基于thor的生成器,似乎无法从正确的目录运行bundle install 当我运行新的[APP_NAME]函数时,它应该创建目录和文件,然后运行bundle install来安装应用程序所需的gems 发电机功能的来源: def create puts "Creating application #{name}" directory 'application', "#{name}" Dir.chdir("#{Dir.pwd}/#{name}")

我正在为一些内部项目构建一个简单的基于
thor
的生成器,似乎无法从正确的目录运行
bundle install

当我运行新的[APP_NAME]函数时,它应该创建目录和文件,然后运行
bundle install
来安装应用程序所需的gems

发电机功能的来源:

def create
  puts "Creating application #{name}"

  directory 'application', "#{name}"

  Dir.chdir("#{Dir.pwd}/#{name}") do
    puts `bundle install`
  end
end
以及运行调用此创建方法的命令的控制台输出:

$ bundle exec bin/my_gem new test_app
Creating application test_app
      create  test_app
      create  test_app/Gemfile
      create  test_app/Guardfile
      create  test_app/README.md
      create  test_app/app/controllers
      create  test_app/app/helpers
      create  test_app/app/models
      create  test_app/app/views
Using thor (0.14.6) 
Using my_gem (0.0.1) 
Using bundler (1.1.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
如您所见,它正在运行
bundle install
,但它运行在我当前的目录(
thor
bundler
my_gem
),而不是
test_app
目录(
guard
guard coffeescript
guard less
,以及其他目录)

运行其他命令,如
ls
pwd
可获得预期结果:

Gemfile
Guardfile
README.md
app


不确定这是否有什么不同,但我使用RVM来管理我的红宝石。

请试试这个,我肯定会帮你的

      rvm gemset create app_name


      rvm use ruby-1.9.2@app_name
Ruby版本你还用了什么

然后安装bundler-gem

      gem install bundler.           

然后捆绑安装并运行服务器。

听起来你的应用程序已经在使用bundler了,而你的bundler中有一个bundler问题。试试这个:

Bundler.with_clean_env do
  puts `bundle install`
end

我猜发生的事情是,您的外部绑定器将
BUNDLE\u GEMFILE
env变量设置为应用程序的GEMFILE,然后您的内部绑定器最终继承了它。

“不确定这是否有任何区别,但我使用RVM管理我的红宝石。”-是:)是的,当然是管理ruby,但是在rvm的帮助下,你应该创建gemset并使用gemset目录来安装gem,你现在不会遇到任何问题。我正在使用一个新的gemset,它已经安装了
thor
bundler
。问题不是捆绑包没有安装,而是生成器没有在适当的目录中运行命令,因此,它使用了错误的Gemfile。哦,我遇到了这个问题,然后我使用了这个技巧。通过命令行转到应用程序的目录,逐个安装所有gem,并且确保在任何gem之后,它都安装在正确的gemset目录中。我正在尝试将其自动化,这就是为什么我试图以编程方式运行
bundle install
,就像rails在其生成器中所做的那样。
Bundler.with_clean_env do
  puts `bundle install`
end