0

Rails ver: 5.1.4
I want to link a image from 'app/assets/images/logo.png'.
File index.html.erb

<body>
    <%= link_to image_tag('logo.png') %>
</body>

When I run, It give me a Error: Encoding::InvalidByteSequenceError and description show "\xB4" on UTF-8. I thinks it's an Encoding error when I save file. I tried to save all of my file in UTF-8 (editor SublimeText) but it still not working. Is anyone meet same error?
Thanks everyone !

4 Answers 4

1

You may have to give the root_path as well like below

<body>
   <%= link_to image_tag('logo.png'), root_path %>
</body>
Sign up to request clarification or add additional context in comments.

1 Comment

can you try putting a *.jpg file instead and see. Also check the permissions and the size of the image. You may be right, it may be related sublime as well. Try using 'Notepad++' or vim
1

I have done this like:

  <%=link_to image_tag('logo.png'), buildings_path %>

This link will display as image and will directed to given path if clicked.

Comments

1
<%= link_to image_url('logo.png') %>

Is this what you want ?

NB : image_tag generates an <img> HTML element with your image as src, thus you were trying to put an <img> as href of your link.

Comments

0

I think you missed the url on click image it will be redirected though you can use give solution , and make sure you have given correct path of image logo.png

<body>
  <%=link_to your_link_path do %>
    <%=image_tag('logo.png') %>
  <%end%>
</body>

5 Comments

Thanks you but still not working. I make sure path of image logo.png is correct. If the path don't correct, it will give an error.
Have you replaced your_path with your own path
Yeah, I have. Do you have any idea?
<meta charset="utf-8"> add this in your application.html.erb in your header tag
its a similar question like this stackoverflow.com/questions/41590314/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.