hujihuji
hujihuji

Reputation: 81

An image does't show up on my local server in Rails

I'm trying to show up an image(lady enjoy.png) I set on image file in asset file but which does't appear. I think the codes are correct though.

<article class="project2">
  <div class="media">
    <a href="#">
      <img src="<% asset_path "ladyenjoy.jpg" %>" alt="" title="">
    </a>
  </div>
  <div class="details">
    <a href="work_details.html">
      <h1>enjoy it!</h1>
    </a>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo ...</p>
  </div>
</article>

Upvotes: 1

Views: 43

Answers (1)

Arslan Ali
Arslan Ali

Reputation: 17802

You not only need to execute the code, but also put it back there as well, and in that case you need an equal(=) sign there.

<%= asset_path "ladyenjoy.jpg" %>

<% %> will execute the code, but didn't print/put anything to your HTML file. But in case, if you would like to get return something form that execution like the returned result from the method asset_path, you will need to use <%= %>.

Edit:

For what you are doing, a better would be to use image_tag instead of asset_path. image_tag just needs the name of the image, and it is gonna take care of the rest of the things.

<%= image_tag 'ladyenjoy.jpg' %>

Upvotes: 3

Related Questions