在seeds.rb 中使用回形针 [英] Using Paperclip within seeds.rb

查看:72
本文介绍了在seeds.rb 中使用回形针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的 seeds.rb 文件中有以下条目:

Let's says I have the following entry in my seeds.rb file :

Image.create(:id => 52, :asset_file_name => "somefile.jpg", :asset_file_size => 101668, :asset_content_type => "image/jpeg", :product_id => 52)

如果我播种它,它会尝试处理指定的图像,我会收到此错误:

If I seed it, it tries to process the image specified, I get this error :

No such file or directory - {file path} etc...

我的图像已备份,所以我真的不需要创建它们;但我需要记录.我无法在我的模型中评论回形针指令;然后它起作用了;但我想可能还有另一种解决方案.

My images are backed up, so I don't really need to create them; but I need the record though. I can't comment the paperclip directive in my model; then it works; but I guess there might be another solution.

是否有另一种模式可以实现?或者告诉回形针不要处理图像的周转?

Is there another pattern to follow in order to accomplish it ? Or a turnaround to tell paperclip not to process the image ?

推荐答案

与其直接设置资产列,不如尝试利用回形针并将其设置为 ruby​​ File 对象.

Rather than setting the asset columns directly, try leveraging paperclip and setting it as ruby File object.

Image.create({
  :id => 52, 
  :asset => File.new(Rails.root.join('path', 'to', 'somefile.jpg')),
  :product_id => 52
})

这篇关于在seeds.rb 中使用回形针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆