[英]How to store an array of images in Rails 3?
I have a model Book that has n screenshots. 我有一本具有n个屏幕截图的模型书。
Each screenshot is an image. 每个屏幕截图都是一张图片
I would like to use a image plugin (eg paperclip) 我想使用图片插件(例如回形针)
Can I store a paperclip image in an array and serialize? 我可以将回形针图像存储在数组中并序列化吗?
Is there a better way? 有没有更好的办法?
Thanks 谢谢
You should probably create a table and model for each Screenshot
and then set up a has_many
relationship from Book
to Screenshot
, and a belongs_to
from Screenshot
to Book
. 您应该为每个Screenshot
创建一个表和模型,然后设置从Book
到Screenshot
的has_many
关系,以及从Screenshot
到Book
的belongs_to
。
Then Screenshot
would use the paperclip plugin to handle the attachment in whatever way you like, though I recommend storing it either on the filesystem or on something like Amazon's S3, both of which the plugin should help you do. 然后, Screenshot
将使用回形针插件以您喜欢的任何方式处理附件,尽管我建议将其存储在文件系统或Amazon S3之类的文件上,这两种插件都应为您提供帮助。 Whatever you do, don't store them in the database as it's horribly inefficient and doesn't let you take advantage of fast file servers like Apache, Nginx, or S3. 无论您做什么,都不要将它们存储在数据库中,因为它效率极低,并且不能让您利用Apache,Nginx或S3等快速文件服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.