问题
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