rails 3.1 中的图像 - 转移到生产 [英] Images in rails 3.1 - moving to production

查看:36
本文介绍了rails 3.1 中的图像 - 转移到生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文章有图片.我将图像放在 app/assests/images 中,并将它们的位置存储在数据库中的一个字段中.

My articles have images. I put the images in app/assests/images and store their location in a field in the database.

然后我可以使用:

<%= image_tag(@article.image) %>

但是当我移动到生产服务器时,我的图像都没有显示!服务器正在寻找 assets/blank-d5dd6e3683b4753dfde3c70cf61f99b6.png 而不是 blank.png,但它不可用.

But when I move to the production server, none of my images show up! The server's looking for assets/blank-d5dd6e3683b4753dfde3c70cf61f99b6.png rather than blank.png and it isn't available.

我该如何排序?

推荐答案

这是我在 Rails 3.1 发布时遇到的问题.

This is a problem I ran into when Rails 3.1 was released.

如果您的资产是您手动放置的,那么您所要做的就是运行:

If your assets are manually placed by you then all you have to do is run:

rake assets:precompile

这会将您的资产预编译为 public/assets.

This will precompile your assets into public/assets.

最好在您的生产服务器上进行预编译,这样您的开发服务器上就没有不必要的文件.

It's best to precompile on your production server so you don't have unessential files on your development server.

如果您使用 Paperclip 之类的文件上传图片,请不要使用资产文件夹.

If you are uploading images using something like Paperclip, then don't use the asset folder.

您需要将图像放在公共文件夹中.在你的情况下可能 public/assets/articles

You need put your images in the public folder. In your case probably public/assets/articles

这篇关于rails 3.1 中的图像 - 转移到生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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