开发者

ImageScience breaks on update to Rails 3

I had a working (and working well) ImageScience install, that did some simple resizing to various dimensions of images, and then copying them to different directories. All very simple. This small and simple routine was in a rake task. Upon update to Rails 3, this rake task will still work (it does some AR inserts and audio encoding as well), but the image_science require fails with a message like this,

"require on /home//.ruby_inline/Inline_ImageScience_cdab.so failed"

I've ruled out a duff ImageScience install, as I can go into IRB and do some simple calls to ImageScience and make thumbnails. The remainder of the rake task works as well as it did before if I comment out any mention of requiring 'image_science' or the ImageScience routine.

the output from rake on failure is this,

/var/lib/gems/1.8/gems/RubyInline-3.8.6/lib/inline.rb:513:in `load'
/var/lib/gems/1.8/gems/RubyInline-3.8.6/lib/inline.rb:829:in `inline'
/var/lib/gems/1.8/gems/image_science-1.2.1/lib/image_science.rb:90
...
<active_support complaints >
...
/home/<user>/RailsApps/marlow/lib/tasks/flac_import.rake:2
...
<rails complaints>
...
/home/<user>/RailsApps/marlow/Rakefile:7
...
<standard complaints to end>
开发者_运维技巧

the Rakefile in the rails app root is a stock and standard Rails 3 Rakefile, like this,

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

Marlow::Application.load_tasks

the last line is line 7.

I'm kind of stumped as to what's breaking it, and Google doesn't seem to shed anything. Does anyone know why RubyInline is complaining? Or why this once working Rake task is suddenly unhappy how ImageScience is being called? OS is Ubuntu 10.10, but it was all working prior to the Rails 3 upgrade.

Thanks in advance


This does seem to be the problem, but there is a simpler fix I found from perusing the comments at carlhuda issues 431

I had the same problem and it worked for me. Simply change the require method to be Kernel.require.

After that there's no need to pepper your code with require image_science statements.


There is a fix, but you'll need to jump through few hoops.

First delay image_science load:

gem 'image_science', :require => false

Then monkey patch ruby-inline (which image_science relies on). Place this code in config/initializers/ruby_inline_hack.rb:

class Inline::C
  def load
    require "#{so_name}"
    #below is the original version which breaks
    #require "#{so_name}" or raise LoadError, "require on #{so_name} failed"
  end
end

Then require 'image_science' wherever you're using it. And voila.


One note on aremave's answer:

It looks like the original code has a bug! It's not using short-cut-evaluation!

class Inline::C
  def load
    require "#{so_name}" || raise LoadError, "require on #{so_name} failed"
  end
end

Notice the || , which will stop the evaluation of the logical expression if the first part is true. If there is an 'or' in the same place, the second part of the expression will always be evaluated, hence the error you're seeing...


as seen on bundler issue tracker, it worked for me.

Point your gem file to https://github.com/asynchrony/image_science We rebuilt image science without ruby inline.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜