Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Created December 8, 2016 10:38
Show Gist options
  • Select an option

  • Save bluerabbit/8b0aa17a1a75819972e693b11d1e9cea to your computer and use it in GitHub Desktop.

Select an option

Save bluerabbit/8b0aa17a1a75819972e693b11d1e9cea to your computer and use it in GitHub Desktop.
Railsで文字エンコードShift-JISでレンダリングする方法
class YourController < ApplicationController
  after_action :change_charset_to_sjis, only: [:index]

  def index
  end

  private

  def change_charset_to_sjis
    headers["Content-Type"] = 'text/html; charset=Shift_JIS'
    response.body           = response.body.encode(Encoding::SHIFT_JIS)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment