06 Jun 2013, 03:39
Generic-user-small

Brian Smith (1 post)

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?

06 Jun 2013, 07:06
Generic-user-small

Roger McDonald (8 posts)

Hi,

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.

12 Jun 2013, 13:51
Generic-user-small

Steve Holland (9 posts)

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') %>
12 Jun 2013, 17:58
Samr_small_pragsmall

Sam Ruby (584 posts)

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.

13 Jun 2013, 07:31
Generic-user-small

Ignacio R (2 posts)

Hi guys,

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:

Why there is no assets/images directory in Rails 4.0 RC1

…which leads you to this:

generate ‘app/assets/images’ directory when creating new rails app

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!

13 Jun 2013, 08:34
Generic-user-small

Steve Holland (9 posts)

Hi Sam,

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.

Thanks Steve

13 Jun 2013, 11:02
Generic-user-small

Steve Holland (9 posts)

Hi all,

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.

Thanks Steve

13 Jun 2013, 11:39
Generic-user-small

Ignacio R (2 posts)

Steve,

Your solution works like a charm! Thanks a lot!

Sam,

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?

13 Jun 2013, 12:14
Samr_small_pragsmall

Sam Ruby (584 posts)

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.

13 Jun 2013, 12:42
Generic-user-small

Steve Holland (9 posts)

@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