为什么我可以使用irb的RMagick而不是rails console?

时间:2012-07-09 07:27:24

标签: ruby-on-rails ruby rmagick

ruby​​ 1.9.2p320 rails 3.0.8 Fedora发布16(凡尔纳)

做的:

yum install imagemagick yum安装ImageMagick-devel 宝石安装RMagick完全没有问题

我可以从独立的Ruby程序运行RMagick,但是在Rails中运行Ruby(使用 同样的翻译)找不到RMagick:

gremlin:eric cars01 $ irb
irb(main):001:0> require 'RMagick'
=> true
irb(main):002:0> Magick::Version
=> "RMagick 2.13.1"
irb(main):003:0> $".grep(/Magick/)
=> ["/usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1/lib/RMagick2.so", "/usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1/lib/RMagick.rb"]
irb(main):004:0> 
gremlin:eric cars01 $ rails console
Loading development environment (Rails 3.0.8)
irb(main):001:0> require 'rubygems'
=> nil
irb(main):002:0> require 'RMagick'
LoadError: no such file to load -- RMagick
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:239:in `require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:239:in `block in require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.8/lib/active_support/dependencies.rb:239:in `require'
    from (irb):2
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.8/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `'

如果我把RMagick放在Gemfile中,无论是否有版本,bundle都会说 在机器上找不到宝石。但它适用于其他宝石。

任何人都有任何想法为什么Ruby可以在Rails之外加载RMagick但不在其中?

与此同时,在加载之前将路径推送到$ RMag的超酷解决方法是有效的。

2 个答案:

答案 0 :(得分:2)

在Gemfile中添加此行

gem "rmagick"

然后bundle install

答案 1 :(得分:0)

你的问题是你可能有2+红宝石,请查看以下内容:

  • 哪个红宝石
  • 哪个irb
  • 哪个捆绑
  • 哪个宝石

他们肯定在不同的地方。你必须确保他们使用相同的环境。