4

I am trying to follow Agile development using rails 5.0 book. There I have loaded images inside app/assets/images directory manually just as told in the book.

Following is the line where it is showing error.

      <%= image_tag(product.image_url, class: 'list_image') %>

As I mentioned I loaded images called for ex image.jpg, and it throwing

ActionController exception caught

Sprockets::Rails::Helper::AssetNotFound in Products#index

The asset "image.jpg" is not present in the asset pipeline.

When I checked in db seeded there is a image with url image.jpg but it is throwing error.

user3576036
  • 1,335
  • 2
  • 23
  • 51
  • What is the HTML generated with that in the console? – Pavan Jul 02 '17 at 19:18
  • you mean you want me to `inspect` the error page and tell ? – user3576036 Jul 02 '17 at 19:25
  • No. I mean the equivalent HTML code that is generated. If you inspect it you can see. – Pavan Jul 02 '17 at 19:26
  • `
    <%= image_tag(product.image_url, class: 'list_image') %>
    `
    – user3576036 Jul 02 '17 at 19:27
  • Do you use Paperclip for file attachments ? or do you store the image name Inside `image_url` field of Product model ? because in this case you have to make sure your image is located in the Rails pipeline (such `app/assets/images` ) .. or maybe do you store image as blob in database ?? – Maxence Jul 02 '17 at 20:52
  • For now I am just using them inside `app/assets/images`. They are just some manual added test data. So I haven't implemented paperclip yet. – user3576036 Jul 03 '17 at 02:18
  • `image_url` column has the name of the image file which are in `app/assets/images` – user3576036 Jul 03 '17 at 02:19
  • well basically you just have to make sure "image.jpg" is located in `app/assets/images` I can't see any other reason triggering this error message ... check spelling, upper case ... – Maxence Jul 03 '17 at 11:17
  • if you can't find any error, you would probably check your asset pipeline https://stackoverflow.com/questions/9708618/why-wont-rails-find-my-assets Please also confirm ou have your `image_tag` Inside a view file and maybe paste all your code – Maxence Jul 03 '17 at 11:25

2 Answers2

1

I ran into this issue myself whilst following the book. You need to ensure that you have a file called image.jpg in the location app/assets/images. It's no good just having the filename in the image_url field in the database.

Simon Cooper
  • 1,574
  • 4
  • 24
  • 53
0

Remember to run bin/rails db:seeds after making changes to the seeds.rb file. Seems straight forward but as a new developer I sometimes forget (for about 30 mins) and wonder why it's not working.

JM-Sully
  • 5
  • 4