0

I have the file "test.gif" in the "/images". In the view, I am using the following command to view it

<%= image_tag 'test.gif' %>

which renders

<img src="/images/test.gif" alt="Test">

But the image is not displayed. Going to "src" address, I get the error message:

No route matches [GET] "/images/test.gif"

How to solve this problem?

Edit:

My route.rb:

Rails.application.routes.draw do
  resources :products
end
macabeus
  • 4,156
  • 5
  • 37
  • 66

3 Answers3

0

This should work:

<%= asset_path('test.gif') %>
Cyzanfar
  • 6,997
  • 9
  • 43
  • 81
  • 1
    I've tried using this command and moving the image to the root, but did not solve the problem. – macabeus Jun 03 '15 at 04:35
  • You shouldn't need to move it in your root directory. Leaving it inside the images folder should still work – Cyzanfar Jun 03 '15 at 04:36
  • Sorry. I meant "copied". I have the same image in the images directory as well. And that does not render the HTML code to display the image, so I tried with `<%= image_tag asset_path('test.gif') %>` – macabeus Jun 03 '15 at 04:46
0

Try this

Take the slash out in front of the images

<img src="images/test.gif" alt="Test">
Nitin Rajan
  • 309
  • 2
  • 18
0

I resolved my problem.

It is mandatory to use the folders /app/assets or /public. Other beyond this Rails does not allow. So I copied the image to /public/test.gif and used the command

<%= image_tag '/uploads/test.gif' %>
macabeus
  • 4,156
  • 5
  • 37
  • 66