Ruby on Rails在UTF-8中无效的字节序列

时间:2017-07-27 11:52:15

标签: ruby-on-rails ruby-on-rails-5 passenger

我在我的网络服务器上开发我的ruby应用程序,一切正常。一旦我将它部署到生产网络服务器,并且与乘客一起运行,我会收到以下错误:

I, [2017-07-27T13:15:14.594740 #26105]  INFO -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef] Started GET "/" for 92.50.69.170 at 2017-07-27 13:15:14 +0200

I, [2017-07-27T13:15:14.597422 #26105]  INFO -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef] Processing by NewsController#index as HTML

I, [2017-07-27T13:15:14.605119 #26105]  INFO -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef]   Rendering news/index.html.erb within layouts/application

I, [2017-07-27T13:15:14.606419 #26105]  INFO -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef]   Rendered news/index.html.erb within layouts/application (1.0ms)

> I, [2017-07-27T13:15:14.650500 #26105]  INFO -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef] Completed 500 Internal Server Error in 53ms (ActiveRecord: 0.0ms)

F, [2017-07-27T13:15:14.652101 #26105] FATAL -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef]   

F, [2017-07-27T13:15:14.652170 #26105] FATAL -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef] ActionView::Template::Error (invalid byte sequence in UTF-8):

F, [2017-07-27T13:15:14.652565 #26105] FATAL -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     15: 
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     16: 
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     17: 
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     18:   <%= stylesheet_link_tag    'application', media: 'all', "data-turbolinks-track" => true %>
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     19: 
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     20:   <%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
[3cbea21c-5d64-41ba-ac9e-69887cc9ebef]     21: 

F, [2017-07-27T13:15:14.652600 #26105] FATAL -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef]   

F, [2017-07-27T13:15:14.652633 #26105] FATAL -- : [3cbea21c-5d64-41ba-ac9e-69887cc9ebef] app/views/layouts/application.html.erb:18:in `_app_views_layouts_application_html_erb__1631551722207135725_70167078217020'

我在enviroment.rb文件中改变了所有内容:

Encoding.default_internal = 'utf-8'
Encoding.default_external = 'utf-8'

我使用Ruby 2.3.1(p112)和Rails 5.0。

你能告诉我这里有什么不对吗?

祝你好运

1 个答案:

答案 0 :(得分:0)

看看这个答案,它将帮助您了解如何使用Ruby调试器进行调试,并且您将能够更轻松地了解您的问题。

How to debug your code

从它的外观来看,你的视图中有一些代码与UTF-8兼容,可能来自你的数据库?