Rails中的回形针问题

时间:2015-11-12 14:51:50

标签: ruby-on-rails paperclip

我为我的rails项目安装了paperclip并完成了编码部分,以便按照教程使用它。但是当我以前看到Item的模式(其中包含图像作为列)时,它创建了四个其他列,如image_file_name,并为它们分配了各自的数据类型。但是名为image的列没有与之关联的任何数据类型并且保持为空。我在哪里错过了什么。另外,我想知道图像是如何存储在回形针内部的(例如:作为字符串)。

1 个答案:

答案 0 :(得分:1)

回形针迁移会创建这4个字段供内部使用:

t.string   "image_file_name"
t.string   "image_content_type"
t.integer  "image_file_size"
t.datetime "image_updated_at"

如果您对保存文件的位置感到好奇,可以尝试打开rails控制台并访问上传图像的url属性。我不知道您添加附件的模型名称是什么,但让我们称之为UploadedImage并且您的图片附件被声明为has_attached_file image:< / p>

$ rails c
irb> UploadedImage.last.url

这应该打印出存储图像的路径。

回形针自述文件中有一节介绍存储:https://github.com/thoughtbot/paperclip#understanding-storage

默认情况下,该位置为:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename