ImageScience 在更新 Rails 3 时中断

发布于 2024-10-04 10:35:47 字数 1441 浏览 1 评论 0原文

我有一个工作(并且工作良好)的 ImageScience 安装,它对图像的各种尺寸进行了一些简单的调整大小,然后将它们复制到不同的目录。一切都很简单。这个小而简单的例程是在 rake 任务中。更新到 Rails 3 后,这个 rake 任务仍然可以工作(它也会执行一些 AR 插入和音频编码),但是 image_science require 失败,并显示如下消息:

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

我已经排除了安装 ImageScience 的可能性,因为我可以进入 IRB 对 ImageScience 进行一些简单的调用并制作缩略图。如果我注释掉任何需要“image_science”或 ImageScience 例程的提及,则 rake 任务的其余部分会像以前一样工作。

rake 失败时的输出是这样的,

/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>

rails 应用程序根目录中的 Rakefile 是一个标准的 Rails 3 Rakefile,就像这样,

# 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

最后一行是第 7 行。

我有点困惑是什么破坏了它,而 Google 没有似乎没有流下任何东西。有谁知道为什么 RubyInline 会抱怨?或者为什么这个曾经有效的 Rake 任务突然对 ImageScience 的调用方式不满意?操作系统是 Ubuntu 10.10,但在 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往昔成烟 2024-10-11 10:35:47

这似乎确实是问题所在,但我通过仔细阅读 carlhuda issues 的评论发现了一个更简单的解决方案431

我也遇到了同样的问题,它对我有用。只需将 require 方法更改为 Kernel.require 即可。

之后,无需在代码中添加 require image_science 语句。

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.

晨光如昨 2024-10-11 10:35:47

有一个修复方法,但您需要克服一些困难。

第一次延迟 image_science 加载:

gem 'image_science', :require => false

然后是猴子补丁ruby-inlineimage_science所依赖的)。将此代码放入 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

然后无论您在何处使用它,require 'image_science'。瞧。

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.

尾戒 2024-10-11 10:35:47

关于 aremave 的答案的一点说明:

看起来原始代码有一个错误!它不是使用捷径评估!

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

注意 || ,如果第一部分为真,这将停止逻辑表达式的求值。
如果同一位置有“或”,则表达式的第二部分将始终被计算,
因此您看到的错误...

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...

貪欢 2024-10-11 10:35:47

正如在 bundler 问题跟踪器 上看到的,它对我有用。

将您的 gem 文件指向 https://github.com/asynchrony/image_science 我们重建了图像科学没有 ruby​​ 内联。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文