How to fix ActionView :: Template :: Error (incompatible character encodings: ASCII-8BIT and UTF-8)

I get the following error: [ActionView :: Template :: Error (incompatible character encodings: ASCII-8BIT and UTF-8)]

Here is the magazine ...

    Completed 500 Internal Server Error in 318ms 
    Jan 09 23:29:19 burro app/web.1:  ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8): 
    Jan 09 23:29:19 burro app/web.1:       97:         <!-- <td><%= row.notes.gsub("\n", "<br>").html_safe %></td> --> 
    Jan 09 23:29:19 burro app/web.1:       98:       </tr> 
    Jan 09 23:29:19 burro app/web.1:       99:     <% end %> 
    Jan 09 23:29:19 burro app/web.1:      100:   </tbody> 
    Jan 09 23:29:19 burro app/web.1:      101: </table> 
    Jan 09 23:29:19 burro app/web.1:      102:  

HERE CODE:

<td><%= row.notes.force_encoding("utf-8") %></td>
    <!-- <td><%= row.notes.gsub("\n", "<br>").html_safe %></td> -->
  </tr>
<% end %>

Do I have all this in the correct rb and erb files?

<%# encoding: utf-8 %>


config.encoding = "utf-8"

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

@data.each do |sr|
    sr.notes = sr.notes.to_s.force_encoding("UTF-8")
  end

The data in db is encrypted, so I cannot run a query on MongoDB data to find out which special character causes a problem when displaying records?

+1
source share
1 answer

You can try below

config/application.rb should consist

  config.encoding = "utf8"

Also in your environment the file

in config/environments/development.rbor config/environments/production.rbshould have

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

and

Also use below in the .rb file

# encoding: utf-8

It tells ruby to interpret the source of the file as utf-8, even if it doesn't contain any non-ascii characters

in this particular file

, .

0

Source: https://habr.com/ru/post/1530591/


All Articles