RailsによるアジャイルWebアプリケーション開発
で勉強しながら、Railsアプリを作っているが、Railsをバージョンアップ(ver 1.2.3)しているうちに、いつの間にか本書の記述だけでは文字化けするようになってしまった。
それで、やっとこさ解決方法を見つけた。
app/controllers/application.rbを以下のように修正する(情報源)。
なんとなく、コードは理解できるが説明はできない。(-o-)
ブログランキング登録中。

それで、やっとこさ解決方法を見つけた。
app/controllers/application.rbを以下のように修正する(情報源)。
class ApplicationController < ActionController::Base
before_filter :set_charset
before_filter :configure_charsets
# Pick a unique cookie name to distinguish our session data from others'
session :session_key => '_practice_session_id'
private
def set_charset
@headers["Content-Type"] = "text/html; charset=UTF-8"
end
def configure_charsets
@response.headers["Content-Type"] = "text/html; charset=utf-8"
# Set connection charset. MySQL 4.0 doesn't support this so it
# will throw an error, MySQL 4.1 needs this
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
end
end
end
なんとなく、コードは理解できるが説明はできない。(-o-)
ブログランキング登録中。

この記事のトラックバックURL
http://konohaotoshi.blog69.fc2.com/tb.php/83-cac6370b
この記事にトラックバックする(FC2ブログユーザー)
この記事にトラックバックする(FC2ブログユーザー)
この記事へのトラックバック
