6
votes

ruby 1.9.2p320 rails 3.0.8 Fedora release 16 (Verne)

Did:

yum install imagemagick yum install ImageMagick-devel gem install RMagick with no problems at all

I can run RMagick from standalone Ruby programs, but Ruby in Rails (using same interpreter) can't find 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 `'

If I put RMagick in the Gemfile, with or without its version, bundle says it can't find the gem on the machine. But it works with other gems.

Anyone have any ideas why Ruby can load RMagick outside Rails but not in it?

For the meantime the super-cool workaround of pushing the path to RMagick on $: before loading it works.

2
As xdite points out below, it's because rails console uses a different gem environment. Try running bundle exec irb for a more apt comparison.Ben Taitelbaum
Sure. The problem is that I can't get bundle to create an RMagick gem in vendor/cache. Any suggestions?Eric

2 Answers

3
votes

add this line in your Gemfile

gem "rmagick"

then bundle install

1
votes

your problem is your may have 2+ ruby, check below:

  • which ruby
  • which irb
  • which bundle
  • which gem

They are definitely in different places. You must make sure they are using the same enviorment.