I had to put my images /public/images to get them to show in the app instead of app/assets/images. Is this normal or am I doing something wrong somewhere?
Put all images in the app/assets/images folder. Rails 4 reads images directly from this folder.
Sometimes I have to create this folder manually, as it is not created with a new scaffold. (?)
In your .html.erb, use the image_tag() to call the image - example: < % = image_tag(“imageName.png”) % >. If you are calling the image from the table, use the same image_tag(), but add the reference, i.e < % = image_tag (tutorial.tutorial_image) % >.
This should work - I find that images don’t display if they are not handled this way.
I had to add spaces between the Ruby % tags, as they didn’t display correctly.
I’m having exactly the same issue as Brian.
If the images are located in app/assets/images they do not show. If you then copy them into /public/images as Brian has said, they do show.
I did have to create the /images folder in /assets as the scaffold didn’t do it.
Even if you use the downloaded sample code for index.html.erb which give you this image tag:
<%= image_tag(product.image_url, class: 'list_image') %>
Brian, Steve: by any chance are you saying that you are having a problem in production? Because development should just work. Assets need to be precompiled before use in production.
I am having the very same issue as Brian and Steve.
Sam Ruby said:
bq. …by any chance are you saying that you are having a problem in production?
I am a complete noob so I am not sure if I am in development or production mode. Sam, is there any way to check? Even so, I do believe I should probably be in development mode as I have diligently followed all the steps indicated in the book.
Again, just a theory, but doing my research through the internet, I came across this:
…which leads you to this:
So is there any chance that we’re doing everything right but it’s the actual changes that the rail version is undergoing that make it look for images ina different directory to app/assets/images?
Thanks for your help!
No, not in production. I’m just working through the book in development so far.
Looking at the links that Ignacio posted, it looks like that may well be the issue.
I just though I’d give an update on this because I’ve just tried moving the /images back into /assets and it all seems to be working now without a hitch!
What I think might be the cause is this…
If you already had the server running (which I did), when you manually created the /images folder in /assets, the change isn’t picked up at all. I’ve since come back to it and restarted the server several times as I’ve moved through he book and the /images folder is now recognised.
So for me at least I think the root of the issue is just that the images folder isn’t automagically created when you create your app with the generator.
Hope this help everyone.
Your solution works like a charm! Thanks a lot!
Maybe it would be a good idea to mention in the book to turn off the server when adding external files and then restart it once they have been transferred?
If I can build a test case, I either will fix it or get it to be fixed in the Rails final release. Based on the link above, this might already be fixed in 4.0.0.rc2.
@ignacio - Excellent! Glad I could help.
@Sam - That would be great, thanks for taking the time to look at this for us. It’s much appreciated.
|You must be logged in to comment|