【问题标题】:How to make existing images into paperclip images?如何将现有图像制作成回形针图像?
【发布时间】:2011-09-08 21:14:38
【问题描述】:

在使用带有导轨的回形针之前,我编写了自己的上传脚本,我使用该脚本上传了一批图像并分配给它们各自的对象。但现在我需要将所有图像切换为回形针友好。

有没有一种方法可以在不使用表单的情况下将图像传递给回形针?

Image.all.each do |image|
  image[:file] = image.filename
  image.save
end

我可以遍历图像对象列表并将图像文件重新分配为回形针附件。谢谢。

【问题讨论】:

    标签: ruby-on-rails paperclip


    【解决方案1】:

    鉴于file 是您的回形针对象的名称,我会这样做:

    Image.all.each do |image|
     image.file = File.open("#{Rails.root}/path_to_images/#{image.filename}")
     image.save
    end
    

    【讨论】:

    • 它可以工作,但会复制文件,有更好的方法吗?
    • 图片重复?您的源文件夹不应该在 Rails 应用程序中
    • 好的,我明白了。我的源文件夹在我的 Rails 应用程序中,哈哈。谢谢。
    猜你喜欢
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多