简体   繁体   English

UTF-8 在 Ruby on Rails 中的问题

[英]UTF-8 issue in Ruby on Rails

I'm trying to display pieces of text in multiple languages.我正在尝试以多种语言显示文本。 Because they're all European languages i've chosen to stick with UTF-8 encoding for the database and the sources of the data.因为它们都是欧洲语言,所以我选择对数据库和数据源使用 UTF-8 编码。 The Database is MySQL and setup with UTF-8 encoding.数据库为 MySQL 并使用 UTF-8 编码设置。

When looking at the configuration of my RoR project, I can find various settings that tell it to do everything in UTF-8 encoding.查看我的 RoR 项目的配置时,我可以找到各种设置,告诉它以 UTF-8 编码执行所有操作。 The data I've stored in the database comes from an XML file that has the UTF-8 encoding attribute and is created with notepad++ and saved with UTF-8 encoding.我存储在数据库中的数据来自 XML 文件,该文件具有 UTF-8 编码属性,使用记事本++创建并使用 UTF-8 编码保存。

When I retrieve the data from the database however, the output is text withs everal � entities in it.然而,当我从数据库中检索数据时,output 是包含所有实体的文本。 I'm clueless on how to solve this problem.... Below is my environment setup:我对如何解决这个问题一无所知....下面是我的环境设置:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.5.2
  - RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  - INSTALLATION DIRECTORY: c:/Ruby/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: c:/Ruby/bin/ruby.exe
  - EXECUTABLE DIRECTORY: c:/Ruby/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - c:/Ruby/lib/ruby/gems/1.8
     - c:/Users/arne.de.herdt.TENFORCE2/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

If there's anything else needed of info, please ask and i'll update this topic.如果还有其他需要的信息,请询问,我会更新这个主题。 I'm just trying to get the data to be displayed properly.我只是想让数据正确显示。

EXAMPLE: Prüfer f�r die Zerst�rungsfreie Werkstoffpr�fung (m/w) Arbeitsort:D�sseldorf示例: Prüfer f�r die Zerst�rungsfreie Werkstoffpr�fung (m/w) Arbeitsort:D�sseldorf

EDIT: Adding the database.yml file output编辑:添加 database.yml 文件 output

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: ESCO_development
  pool: 5
  username: hidden_username
  password: hidden_password
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: ESCO_test
  pool: 5
  username: hidden_username
  password: hidden
  host: localhost

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: ESCO_production
  pool: 5
  username: hidden_username
  password: hidden
  host: localhost

All your database configuration seems fine, did you check if your browser isn't forcing any charset encoding?您所有的数据库配置似乎都很好,您是否检查过您的浏览器是否没有强制任何字符集编码? Try changing the charset manually in your browser.尝试在浏览器中手动更改字符集。

Also, check your html files to find any other charset encoding that isn't utf8此外,检查您的 html 文件以查找任何其他不是 utf8 的字符集编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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