简体   繁体   English

Rails 3.1中的图像-投入生产

[英]Images in rails 3.1 - moving to production

My articles have images. 我的文章有图片。 I put the images in app/assests/images and store their location in a field in the database. 我将图像放在app / assests / images中,并将其位置存储在数据库的一个字段中。

Then I can display them in by using: 然后,我可以使用以下命令显示它们:

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

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. 服务器正在寻找资产/blank-d5dd6e3683b4753dfde3c70cf61f99b6.png而不是blank.png,它不可用。

How do I sort this? 我该如何分类?

This is a problem I ran into when Rails 3.1 was released. 我在发布Rails 3.1时遇到了这个问题。

Normal assets 普通资产

If your assets are manually placed by you then all you have to do is run: 如果资产是由您手动放置的,那么您所要做的就是运行:

rake assets:precompile

This will precompile your assets into public/assets . 这会将您的资产预编译为public/assets

It's best to precompile on your production server so you don't have unessential files on your development server. 最好在生产服务器上进行预编译,以免开发服务器上没有不必要的文件。

Uploaded assets 上传的资产

If you are uploading images using something like Paperclip , then don't use the asset folder. 如果您要使用Paperclip之类的图片上传图片,请不要使用资产文件夹。

You need put your images in the public folder. 您需要将图像放在公用文件夹中。 In your case probably public/assets/articles 在您的情况下,可能是public/assets/articles

Further Info 进一步的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM