简体   繁体   中英

Ruby on Rails - Encoding Error - InvalidByteSequenceError - \xB4 on UTF-8

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 !

You may have to give the root_path as well like below

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

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.

<%= 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM