Posted on 2008年9月24日 Posted by ちゅう コメントする Posted in Development Tags: Rails Railsはデフォルトで UTF-8 だけれども、たまに何ページか Shift_JIS で出したいみたいなことがあって、そういうのは after_action で処理すればよい。 Controller に以下のように書いておけばよい。上位のとこで書いといて、必要なとこで呼ぶ感じに。 after_filter :change_charset_to_sjis, :only => [:sjis_page] def change_charset_to_sjis response.body = NKF::nkf('-Ws', response.body) headers['Content-Type'] = 'text/html; charset=CP
![Railsでページごとに出力の文字コードを変える方法 | 変なヤバいもんログ](https://cdn-ak-scissors.b.st-hatena.com/image/square/2bb579ca026c1eecce39f8b35818ed91d3490d63/height=288;version=1;width=512/https%3A%2F%2Fecpplus.net%2Fweblog%2Fwp-content%2Fuploads%2F2011%2F08%2Fruby_on_rails.png)