Images in rails 3.1 - moving to production

蓝咒 提交于 2019-11-30 21:11:34

问题


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

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.

How do I sort this?


回答1:


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

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.

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.

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

Further Info

  • RailsGuides - Asset Pipeline


来源:https://stackoverflow.com/questions/8492829/images-in-rails-3-1-moving-to-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!