| 9月 24th, 2008

Railsはデフォルトで UTF-8 だけれども、たまに何ページか Shift_JIS で出したいみたいなことがあって、そういうのは after_filter で定義しておけばよい。

 Controller に以下のように書いておけばよい。上位のとこで書いといて、必要なとこで呼ぶ感じに。

  after_filter :change_charset_to_sjis, :only => [:sjis_page]
  protected
  def change_charset_to_sjis
    response.body = NKF::nkf('-Ws', response.body)
    headers["Content-Type"] = "text/html; charset=Shift_JIS"
  end

There are no comments yet, add one below.

Comments are closed.

Leave a Comment


download the hurt locker  
UA-682965-1