Dana Nourie
Dana Nourie

Reputation: 35

Image not showing in Rails 4.1.1

I'm following a tutorial: http://tutorials.jumpstartlab.com/projects/merchant.html, where we call product images like this:

<%= image_tag "products/#{product.image_url}" %>

That should work, but I get this 404 error, and this shows up in the console:

GET http://localhost:3000/images/products/%20purple_grapes.jpg

What is that %20 in there. When I hard code the image name, it works. Rails is looking in the right place for the image, which is /assets/images/products/ but the file name should be purple_grapes.jpg, not %20purple_grapes.jpg

This problem is driving me batty. I've done this kind of code before calling images and not had this problem. Any idea why this isn't working? I read through The Assets Pipline and according to it this code is correct.

Thank you!

Upvotes: 0

Views: 43

Answers (1)

tirdadc
tirdadc

Reputation: 4703

You probably just entered a space before your file name in the text field.

To avoid this, you can add a validator to your field or force strip on it to avoid leading/ending whitespace.

Upvotes: 2

Related Questions