omegalul
omegalul

Reputation: 27

how to insert image in rails

Using Rails, I am creating my first web-site. And I have a problem like this: I can't insert an image in my page (index.html.erb).

I put an image named "main.png" in directory "app/assets/images", and wrote that:

<img src="main.png">

But my image isn't displayed correctly. What I'm doing not right?

Upvotes: 0

Views: 4943

Answers (2)

nigal
nigal

Reputation: 181

You should use Rails helpers as markets pointed out.

By the way, the name of the image file should be the same you use as the parameter of image_tag method. You are referencing your image as main.png when the image file is main.jpg

<%= image_tag "main.jpg" %>

Upvotes: 0

markets
markets

Reputation: 7033

You should use the provided helpers by Rails to "automagically" detect paths, fingerprints, ...:

<%= image_tag "main.png" %>    

Anyway, I recommend you to read the asset pipeline guides to understand how the assets works in Rails: http://guides.rubyonrails.org/asset_pipeline.html

Upvotes: 2

Related Questions