Hello,
I’m a beginner to Rails.
I has a problem about unicode when I tried some example code like
below:
say_controller.rb:
class SayController < ApplicationController
def list
@files = Dir.glob(’*’)
end
end
application.rb:
class ApplicationController < ActionController::Base
Pick a unique cookie name to distinguish our session data from
others’
session :session_key => ‘_HelloRails_session_id’
before_filter :configure_charsets
def configure_charsets
response.headers[“Content-Type”] = “text/html; charset=utf-8”
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute ‘SET NAMES utf8’
end
end
end
list.rhtml:
File List-
<% for file in @files %>
- <%= file %> <% end %>
When there is a directory with Chinese characters, I got wrong
characters (the are in GB18030), why it was not in UTF-8?