有谁能让 Attachment_fu 与 Rails 3 一起使用吗?

发布于 2024-11-16 03:00:25 字数 588 浏览 2 评论 0原文

我有一个 Rails 应用程序,正在从 Rails 2.3.5 升级到 Rails 3。它使用 Attachment_fu 进行文件上传。我们试图在不更改数据库的情况下进行此转换,因此我想避免此时更改为回形针或载波。

有人成功地将 Attachment_fu 与 Rails 3 和 Ruby 1.9.2 一起使用吗?我们使用的是最新版本的attachment_fu,声称适用于rails 3和ruby 1.9.2,但在任何包含文件上传的表单上都会收到“TypeError(无法将 nil 转换为整数):”。

之前问题的所有答案似乎都是“只需切换到回形针或载波”,如下所示: Attachment_fu 或 Paperclip for Rails3 或者 TypeError(无法将 nil 转换为 Integer):

谢谢!

I have a rails application that is being upgraded from Rails 2.3.5 to Rails 3. It uses attachment_fu for file uploads. We're trying to do this conversion without making DB changes, so I'd like to avoid changing to paperclip or carrierwave at this time.

Has anyone succeeded in using attachment_fu with Rails 3 and Ruby 1.9.2? We're using the most recent version of attachment_fu that claims to be ok for rails 3 and ruby 1.9.2, but getting 'TypeError (can't convert nil into Integer):' on any forms that include a file upload.

All the answers to previous questions seem to be 'just switch to paperclip or carrierwave' as in:
Attachment_fu or Paperclip for Rails3
or
TypeError (can't convert nil into Integer):

Thanks!

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

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

发布评论

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

评论(3

戈亓 2024-11-23 03:00:25

我进行了以下更改,并且有效

attachment_fu.rb

def temp_path
  p = temp_paths.first
  if p.is_a?(ActionDispatch::Http::UploadedFile) # Rails 3.0.3 compatability fix
    p.tempfile.path
  else
    p.respond_to?(:path) ? p.path : p.to_s
  end
end

我还将 returning filename.strip do |name| 更改为 filename.strip.tap do |name|< /code>

init.rb

def make_tmpname(basename, n)
  ext = nil
  n ||= 0
  sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s| ext = s; '' }, $, n, ext)
end

我在 github 上做了一个分支并进行了这些更改
https://github.com/debprado/attachment_fu

I made the following changes and it worked

attachment_fu.rb

def temp_path
  p = temp_paths.first
  if p.is_a?(ActionDispatch::Http::UploadedFile) # Rails 3.0.3 compatability fix
    p.tempfile.path
  else
    p.respond_to?(:path) ? p.path : p.to_s
  end
end

I also changed returning filename.strip do |name| to filename.strip.tap do |name|

init.rb

def make_tmpname(basename, n)
  ext = nil
  n ||= 0
  sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s| ext = s; '' }, $, n, ext)
end

I made a fork on github with this changes
https://github.com/debprado/attachment_fu

岁吢 2024-11-23 03:00:25

Attachment_fu 修补 attachment_fu/init.rb 中的 Tempfile.make_tmpname,它在 1.9.2 中不起作用: sprintf("%d",nil) 失败,在 1.8.7 中此结果表达式为“0”。

解决方法是在 init.rb 中插入一行 from:

sprintf('%s%d-%d%s', File::basename(basename, ext), $, n, ext)

to

n ||= 0
sprintf('%s%d-%d%s', File::basename(basename, ext), $, n, ext)

您可以在此处找到一些讨论 https://github.com/technoweenie/attachment_fu/issues/25

干杯!

attachment_fu patches Tempfile.make_tmpname in attachment_fu/init.rb, and it doesn't work in 1.9.2: sprintf("%d",nil) fails, and in 1.8.7 the result of this expression is "0".

The fix is to insert a line in init.rb from:

sprintf('%s%d-%d%s', File::basename(basename, ext), $, n, ext)

to

n ||= 0
sprintf('%s%d-%d%s', File::basename(basename, ext), $, n, ext)

You can find some of the discussion here https://github.com/technoweenie/attachment_fu/issues/25

Cheers!

东北女汉子 2024-11-23 03:00:25

尝试我支持 Rails 3.2 的 gemified 版本:

https://rubygems.org/gems/pothoven-attachment_fu

Try my gemified version that supports Rails 3.2:

https://rubygems.org/gems/pothoven-attachment_fu

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