将 Paperclip 从插件更新到 gem 时出现问题

发布于 2024-11-25 20:12:49 字数 1516 浏览 3 评论 0原文

我显然在我的应用程序中从 Paperclip 插件版本切换到 gem 版本时遇到了一个巨大的问题。我的印象是,指定版本的插件和 gem 之间应该没有任何区别。然而,我并不认为这是一个简单的过渡。

Rails 2.3.11,Ruby 1.8.7

我使用的插件版本是2.3.3版本,于2010年8月2日升级。尝试将其更新为相同版本的gem基本上杀死了我所有的测试,无法加载未加载附件的工厂模型。看来 validate_attachment_content_type 也在尝试验证附件的存在,但找不到它,所以一切都开始崩溃。再说一遍,使用该插件没有任何问题,而且我在使用它的所有时间里都没有遇到任何问题。另一方面,这个问题似乎在 2.3.4 之后的版本中不会出现。这是另外一系列问题。

基本上,在 2.3.4 及更高版本的所有版本中,我都会遇到以下问题:

can't convert nil into String
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `extname'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `to_file'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/attachment.rb:94:in `assign'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip.rb:279:in `avatar='
/home/joshua/railscamp/app/app/models/organization.rb:311:in `copy_membership'

在访问我的组织模型的所有测试中。

在这种情况下,明显的违规代码试图将成员资格模型从一个组织克隆到另一个组织,其中 * 行是违规调用。

  def copy_membership(membership)
    m = membership.clone
    u = m.user.clone
    u.organization = self
    m.organization = self

    begin
      m.avatar = membership.avatar         *
    rescue RuntimeError
      m.avatar = nil
    end

    m.user = u
    m.save
    m
  end

这对任何人都有意义吗?为什么插件可以工作,但同一版本的 gem 却破坏了一切?

更新:我似乎也没有任何可用的回形针耙任务。有什么想法吗?

I am apparently having a huge problem switching from the plugin version of Paperclip to the gem version in my app. It's been my impression that there should be no difference whatsoever between a plugin and a gem of a specified version. However, I'm not seeing this as an easy transition at all.

Rails 2.3.11, Ruby 1.8.7

The plugin version I am using is version 2.3.3 and was upgraded on August 2, 2010. Attempting to update this to the gem of the same version basically killed all my tests, not being able to load a factory model which did not have its attachment loaded. It appeared that validate_attachment_content_type was also attempting to validate the attachment presence, and couldn't find it, so everything just started breaking. Again, with the plugin there are no problems and I haven't had any problems in all this time we've been using it. On the other hand, this problem seems to not occur past version 2.3.4. That's a whole other set of problems.

Basically, in all versions from 2.3.4 and up I get the problem below:

can't convert nil into String
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `extname'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `to_file'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/attachment.rb:94:in `assign'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip.rb:279:in `avatar='
/home/joshua/railscamp/app/app/models/organization.rb:311:in `copy_membership'

in all my tests that access my organization model.

The apparent offending code in this case is attempting to clone a membership model from one organization to another, with the * line being the offending call.

  def copy_membership(membership)
    m = membership.clone
    u = m.user.clone
    u.organization = self
    m.organization = self

    begin
      m.avatar = membership.avatar         *
    rescue RuntimeError
      m.avatar = nil
    end

    m.user = u
    m.save
    m
  end

Does this make any sense to anyone? Why would the plugin work, but the gem of the same version just wrecks everything?

Update: I also don't appear to have any paperclip rake tasks available. Any ideas?

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

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

发布评论

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

评论(1

苏别ゝ 2024-12-02 20:12:49

事实证明,我们应该检查文件名是否有效,而不是依赖一般的运行时错误来检测头像是否存在。

As it turns out, we should have been checking whether the filename is valid or not, rather than depending on a generic runtime error for detecting avatar presence.

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