Ruby on Rails-是否可以通过表单将图像保存在/app/assets/images中? [英] Ruby on Rails - Is saving images through form in /app/assets/images possible?

查看:75
本文介绍了Ruby on Rails-是否可以通过表单将图像保存在/app/assets/images中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一家销售二手车的小商店开发一个小型的Ruby on Rails应用程序.该站点包含所有可用汽车的列表,包括汽车图像.商店里最多有20辆车.

I'm developing a small Ruby on Rails application for a small shop which sells used cars. The site contains a list with all avalaible cars including an image of the car. There are at maximum 20 cars in the shop.

我读到,不是将图像直接保存在数据库中的最佳实践,最好使用Amazon Web Services之类的云存储服务来存储文件,但是我认为这样的服务对于一个小型网站,一次最多可显示20张图片.

I read that it is not the best practice to save images directly in the database and it's better to store the files with a cloud storage service like Amazon Web Services, but I don't think that a service like this is necessary for a small website with a maximum of 20 images at a time.

我的想法是将图像保存在/app/assets/images中.员工将通过表格上传汽车的信息和图像.是否可以通过Rails中的表单将图像上传并保存在文件夹/app/assets/images中?

My idea is to save the images in /app/assets/images. Employees will upload information and images of the cars through a form. Is it possible to upload and save images in the folder /app/assets/images through a form in Rails?

推荐答案

是否可以通过Rails中的表单将图像上传并保存在文件夹/app/assets/images中?

可能,但不应这样做. /app/assets/images用于您的应用程序资产.它们在部署时进行处理(有指纹等).您不需要对用户文件进行这种处理.

Possible, but shouldn't be done. /app/assets/images is for your app assets. They're processed on deployment (fingerprinted, etc.). You don't need this treatment for user files.

用户上传的内容通常位于/public中的某个位置.例如,/public/uploads/images.

User uploads normally go somewhere in /public. For example, /public/uploads/images.

但是我认为对于一次最多包含20张图片的小型网站,不需要这样的服务

but I don't think that a service like this is necessary for a small website with a maximum of 20 images at a time

Amazon S3具有免费套餐.您的20张图像肯定会放在那里.是的,设置起来有点复杂,但是 是一种最佳做法.

Amazon S3 has a free tier. Your 20 images will surely fit there. Yes, it's a bit complicated to set up, but it is a best practice.

这篇关于Ruby on Rails-是否可以通过表单将图像保存在/app/assets/images中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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