【问题标题】:Rails3 and `cd somehwere && do something`Rails3 和 `cd somehwere && do something`
【发布时间】:2011-01-14 18:22:28
【问题描述】:

我有一个 Rails 项目,它下面有其他项目,子项目有 rake 和 bundler 文件。

当我执行 ruby -e `cd sub-project && rake`ruby -e `cd sub-project && bundle` 时,命令按预期工作,并且使用子项目 rake/bundle 文件。但是,当我从 Rails3 控制台(rails 3.0.3)做同样的事情时,rake 给出错误 no such file to load -- initializer,并且 bundle 的运行就像是从根目录触发一样目录。

我从 Rails2.3.10 控制台尝试了相同的命令,它们按预期工作。 Rails3 在这里做错了吗?

我正在通过 RVM 使用 Ruby 1.9.2。
$ ruby​​ -v
ruby 1.9.2p136(2010-12-25 修订版 30365)[i686-linux]

【问题讨论】:

  • 只是带有自己的 rake 和 bundler 文件的子目录
  • Dir.pwd 在 Rails 控制台中打印什么?

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:
bold_rewards ∴ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
bold_rewards ∴ rake -T | wc -l
      46
bold_rewards ∴ cd vendor/plugins/pretty_flash
pretty_flash ∴ rake -T | wc -l
       6
pretty_flash ∴ cd ../../..
bold_rewards ∴ rails c
Loading development environment (Rails 3.0.3)
>> Dir.pwd
=> "/Users/george/work/bold_rewards"
>> `rake -T | wc -l`.chomp.strip
=> "46"
>> Dir.chdir 'vendor/plugins/pretty_flash'
=> 0
>> Dir.pwd
=> "/Users/george/work/bold_rewards/vendor/plugins/pretty_flash"
>> `rake -T | wc -l`.chomp.strip
=> "6"
>> Dir.chdir Rails.root
=> 0
>> `rake -T | wc -l`.chomp.strip
=> "46"
>> 

不幸的是,我认为 Bundler 是一个更难破解的难题:

increment ∴ cat Gemfile                                                                                                                                                           
source 'http://rubygems.org'

gem 'rails', '3.0.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby', :require => 'sqlite3'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end
increment ∴ cat vendor/subproject_x/Gemfile                                                                                                                                       
source 'http://rubygems.org'

gem 'net-ssh'

increment ∴ rails c                                                                                                                                                               
Loading development environment (Rails 3.0.3)
>> Dir.pwd
=> "/Users/george/tmp/increment"
>> `BUNDLE_GEMFILE="vendor/subproject_x/Gemfile" bundle install`
=> "\e[31mCould not find net-ssh-2.0.24 in any of the sources\e[0m\n"
>> Dir.chdir 'vendor/subproject_x'
=> 0
>> Dir.entries '.'
=> [".", "..", "Gemfile", "Rakefile"]
>> Dir.pwd
=> "/Users/george/tmp/increment/vendor/subproject_x"
>> `BUNDLE_GEMFILE="Gemfile" bundle install`
=> "\e[31mCould not find net-ssh-2.0.24 in any of the sources\e[0m\n"
>> Dir.chdir Rails.root
=> 0
>> Dir.pwd
=> "/Users/george/tmp/increment"
>> `BUNDLE_GEMFILE="vendor/subproject_x/Gemfile" bundle install`
=> "\e[31mCould not find net-ssh-2.0.24 in any of the sources\e[0m\n"
>> quit
increment ∴ cd vendor/subproject_x                                                                                                                                                
subproject_x ∴ bundle install                                                                                                                                                     
Fetching source index for http://rubygems.org/
Installing net-ssh (2.0.24) 
Using bundler (1.0.7) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
subproject_x ∴

【讨论】:

  • 我更新了对 Bundler 的回答。我花了一段时间挖掘 Bundler 源代码,试图找出采购问题,但没有运气。
  • 我找到原因了!! ENV["BUNDLE_GEMFILE"],如果你在 `cd sub-project && bundle install` 之前删除这个键,它会按预期工作。
猜你喜欢
  • 1970-01-01
  • 2011-09-17
  • 2011-11-21
  • 1970-01-01
  • 2015-02-06
  • 2021-09-29
  • 1970-01-01
  • 2013-01-12
  • 1970-01-01
相关资源
最近更新 更多