Encoding::InvalidByteSequenceError in Home#index “

2019-09-15 23:12发布

问题:

I'm new to Ruby on Rails, and have been battling with this issue for a while now.

I have pulled a website from git, and made sure all the dependencies are installed, however, when I run the site, I get the error:

ActionView::Template::Error ("\xA9" on UTF-8)

because of the line linking images using the code image_path("bground2.jpg").

When I remove the image_path("bground2.jpg"), the error is resolved.

I however need image_path("bground2.jpg") and can't do without it.

I have tried the solutions here, but it seems not to work

This is a section of the index.html.erb file, but the error is recurring over all places containing the image_path and image_url:

<%= provide(:title, 'Home') %>
  <section id="slider" class="">
    <div class="img-responsive" style="background-image: url(<%= image_path("bground2.jpg") %>); background-position: 50% 0;height: 500px;">
      <div class="container clearfix">
   <!-- <div class="slider-caption slider-caption-center">
     <!-- <div class="banner heading-block title-center nobottomborder">
            <h1><%= "#{t('.reach_home')}" %></h1>
          </div> --> 

回答1:

So, I solved this by reinstalling the Ruby application.

Don't know what had caused it, but I just reinstalled the application and everything works fine.

Thanks all for the help.



回答2:

I had this very same issue. I identified it to a file I had in my application, actually it was taking place in minified javascript file I had in my Rails app. I open the file in text editor, added a new line and, set the encoding as UTF-8 and saved it, and the problem disappeared.