新手问题 求教 Ruby Rails 大神 require 问题

shlallen · 2013年03月06日 · 最后由 fsword 回复于 2013年03月07日 · 2860 次阅读

我的电脑上有两个 ruby 版本,一个是本机的,一个是电脑上 CloudFoundry 的。我尝试在本机 ruby 版本下使用 activerecord 是么有问题的。但是我在 Cloud Foundry 的 rails 程序中做改动,在里面某个文件下要用到 ActiveRecord,于是我在该文件添加 require‘active_record’并写入相应的代码,最后将本机版本下的 activerecord-3.2.12 拷贝到 cloudfoundry 下的 rubygem 包目录处,然后运行该文件,然后就显示 in 'require',no such file to load-- active_record (LoadError) 请问是什么情况啊?

是不是我在多版本的情况有什么操作有问题?

估计烤错位置了,干嘛不在 cloudfoundry 里 gem install activerecord

#1 楼 @zgm actually,也不行,刚刚又试了一次

这类问题有个辅助的办法,想办法输出一下 load path:

$ irb
head :001 > puts $LOAD_PATH
/home/john/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.1.0
/home/john/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.1.0/x86_64-linux
/home/john/.rvm/rubies/ruby-head/lib/ruby/site_ruby
/home/john/.rvm/rubies/ruby-head/lib/ruby/vendor_ruby/2.1.0
/home/john/.rvm/rubies/ruby-head/lib/ruby/vendor_ruby/2.1.0/x86_64-linux
/home/john/.rvm/rubies/ruby-head/lib/ruby/vendor_ruby
/home/john/.rvm/rubies/ruby-head/lib/ruby/2.1.0
/home/john/.rvm/rubies/ruby-head/lib/ruby/2.1.0/x86_64-linux

CloudFoundry 默认是 ruby 是 1.8,小心中招哦!

#3 楼 @fsword 刚刚尝试了一下,你确定这些路径都是 gem 包的路径吗?

irb(main):001:0> puts $LOAD_PATH
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/x86_64-linux
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1/x86_64-linux
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1
/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-linux
=> nil

但是我真正有 gem 包的目录是:/root/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems

#4 楼 @ywencn 我听别人说 Cloud Foundry 默认的版本号是 ruby 1.9.2p180 阿?你说的 1.8 是这个意思马?

#6 楼 @shlallen 你要自己看的啊。。。

#5 楼 @shlallen gem 有自己的 load 机制,google 一下吧

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 2.1.0 (2013-02-26 patchlevel -1) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/john/.rvm/gems/ruby-head
  - RUBY EXECUTABLE: /home/john/.rvm/rubies/ruby-head/bin/ruby
  - EXECUTABLE DIRECTORY: /home/john/.rvm/gems/ruby-head/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/john/.rvm/gems/ruby-head
     - /home/john/.rvm/gems/ruby-head@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://ruby.taobao.org/"]
  - REMOTE SOURCES:
     - http://ruby.taobao.org/
# /home/john/.rvm/rubies/ruby-head/bin/gem
...
ENV['GEM_PATH']=ENV['GEM_PATH'] || '/home/john/.rvm/gems/ruby-head:/home/john/.rvm/gems/ruby-head@global'
...
需要 登录 后方可回复, 如果你还没有账号请 注册新账号