0

I am a newbie in Ruby on Rails and here is my problems. I am following railstutorial's book and here is my source code

<%= link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/' %>

I want to load a photo which name rails.png, but it does not load as I expected. Could you please give me some ideas? Thank you very much for your comments.

rony36
  • 3,277
  • 1
  • 30
  • 42
Anh Bui
  • 89
  • 1
  • 2
  • 9

1 Answers1

1

You need to have the rails.png image stored in "app/assets/images/rails.png"

Please search more online before asking question

https://guides.rubyonrails.org/asset_pipeline.html

Ruby on Rails displaying image with image_tag src

user3805610
  • 252
  • 2
  • 13
  • Thank you for your comment. Now I can display my picture in my page now, using your document. Here is my code `<%= image_tag "rails.png"%>` But I still have a question, why they gave me "link_to" in my source code if there is no need? – Anh Bui Jul 07 '19 at 11:12
  • The code you put ```<%= link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/' %>```is correct. It create an image that is a link that will redirect to http://rubyonrails.org/. If you don't want your image to be a link just use the image tag on its own. Otherwise use the link_to. More info here https://stackoverflow.com/questions/5386318/how-do-i-turn-an-image-into-a-link-in-rails – user3805610 Nov 19 '19 at 22:22