Ruby-on-rails 在 Rails 中上传图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/969060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image upload in rails
提问by Nave
How do I upload images and zip files in RoR? I am a newbie. So please help. Give me both the view and the controller code example.
如何在 RoR 中上传图像和 zip 文件?我是新手。所以请帮忙。给我视图和控制器代码示例。
Thanks in advance.
提前致谢。
回答by Lee Hambley
Nav,
导航,
Try the paperclip plugin, you can read about it here http://www.thoughtbot.com/projects/paperclip
试试回形针插件,你可以在这里阅读它http://www.thoughtbot.com/projects/paperclip
回答by Cloudinary
We prefer CarrierWavefor image uploads in Rails. Very easy to integrate and very modular. The following post describes a solution for image uploading using CarrierWave while image transformations are done seamlessly in the cloud. Uploaded images are stored in the cloud and delivered through a CDN. No need to install RMagick, MiniMagick and ImageMagick. http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary
我们更喜欢CarrierWave在 Rails 中上传图片。非常容易集成并且非常模块化。下面的文章描述了一种使用 CarrierWave 上传图像的解决方案,同时图像转换在云中无缝完成。上传的图像存储在云端并通过 CDN 交付。无需安装 RMagick、MiniMagick 和 ImageMagick。 http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary
回答by marcgg
ImageMagickis also pretty cool
ImageMagick也很酷
回答by Aaron Saunders
I would recommend paperclip, and the patch that allows you to store the content in the database instead of the file system
我会推荐回形针,以及允许您将内容存储在数据库而不是文件系统中的补丁
http://patshaughnessy.net/paperclip-database-storage
http://patshaughnessy.net/paperclip-database-storage
the link has the view and controller examples that you are looking for
该链接包含您正在寻找的视图和控制器示例
回答by xamenrax
I prefer carrierwave is better to upload images easily. Here's github page, and railscasts pagefor quick start.
我更喜欢载波更容易上传图像。这是github 页面和railscasts 页面以供快速入门。
回答by erik
One option is attachment_fu. It allows you to save your uploaded file to the filesystem, database, or Amazon S3. It also allows you to select which image processor is used, such as RMagick or Minimagick.
一种选择是attachment_fu。它允许您将上传的文件保存到文件系统、数据库或 Amazon S3。它还允许您选择使用的图像处理器,例如 RMagick 或 Minimagick。
The link provides better code than I could here.
该链接提供了比我在这里提供的更好的代码。

