从活动记录中编码差异以查看
Encoding differences from active record to view
来自服务器的特殊字符未正确呈现,但 html 中静态文本中的特殊字符呈现正常。
我的开发库中有一个记录。它的标题是 'Légende'.
[1] pry(main)> Record.last.title
Record Load (0.3ms) SELECT "records".* FROM "records" ORDER BY "records"."id" DESC LIMIT 1
=> "Légende"
[2] pry(main)> Record.last.title.encoding
Record Load (0.2ms) SELECT "records".* FROM "records" ORDER BY "records"."id" DESC LIMIT 1
=> #<Encoding:UTF-8>
当我想在我的视图中#show 它时,它会打印 Le‘gende
。这不是常见的编码问题,因为它不打印 é
或 é
.
此外,如果我从网页复制并粘贴 Le‘gende
,它又会变成 Légende
。很奇怪。
记录#show
def show
@record = Record.find(params[:id])
end
show.html.erb
<h1>Bibliothèque</h1>
<h2><%= @record.title %></h2>
config/application.rb
config.i18n.default_locale = :fr
config.encoding = "utf-8"
layout/application.html.erb
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
application_controller.rb
class ApplicationController < ActionController::Base
# encoding: utf-8
protect_from_forgery with: :exception
end
我不知道从这里到哪里去。
这是一个字体问题。
供将来参考:罪魁祸首是 open sans。
来自服务器的特殊字符未正确呈现,但 html 中静态文本中的特殊字符呈现正常。
我的开发库中有一个记录。它的标题是 'Légende'.
[1] pry(main)> Record.last.title
Record Load (0.3ms) SELECT "records".* FROM "records" ORDER BY "records"."id" DESC LIMIT 1
=> "Légende"
[2] pry(main)> Record.last.title.encoding
Record Load (0.2ms) SELECT "records".* FROM "records" ORDER BY "records"."id" DESC LIMIT 1
=> #<Encoding:UTF-8>
当我想在我的视图中#show 它时,它会打印 Le‘gende
。这不是常见的编码问题,因为它不打印 é
或 é
.
此外,如果我从网页复制并粘贴 Le‘gende
,它又会变成 Légende
。很奇怪。
记录#show
def show
@record = Record.find(params[:id])
end
show.html.erb
<h1>Bibliothèque</h1>
<h2><%= @record.title %></h2>
config/application.rb
config.i18n.default_locale = :fr
config.encoding = "utf-8"
layout/application.html.erb
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
application_controller.rb
class ApplicationController < ActionController::Base
# encoding: utf-8
protect_from_forgery with: :exception
end
我不知道从这里到哪里去。
这是一个字体问题。
供将来参考:罪魁祸首是 open sans。