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. The Database is MySQL and setup with UTF-8 encoding.
When looking at the configuration of my RoR project, I can find various settings that tell it to do everything in UTF-8 encoding. 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.
When I retrieve the data from the database however, the output is text withs everal � entities in it. 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
EDIT: Adding the database.yml file 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
精彩评论