Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I use RMagick from irb but not rails console?

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.

like image 275
Eric Avatar asked Jul 09 '12 07:07

Eric


1 Answers

add this line in your Gemfile

gem "rmagick"

then bundle install

like image 157
xdite Avatar answered Oct 06 '22 01:10

xdite