Forum: Ruby on Rails how to define content charset?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C0a32d16cf74103a6b8f31105cb04875?d=identicon&s=25 Mikhail Shevchuk (Guest)
on 2006-01-25 21:02
(Received via mailing list)
I tried to define koi8-r charset in app/views/layouts/ like this:
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
  <title>Cpu: <%= controller.action_name %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>

But it doesn't work. I suppose WEBrick already sent utf8 charset in it's
header, didn't it?
How can I do the subject?
3f900b38ec3b2c45427c354722fa4ce3?d=identicon&s=25 Tom Fakes (tomfakes)
on 2006-01-25 21:14
(Received via mailing list)
You need to add this to the response headers, either in specific actions
like this:

	def list
		@response.headers["Content-Type"] = "text/html;
charset=koi8-r"
	end


Or in a before filter that you apply to as many actions as you want:

	class FooController < ApplicationController
	  before_filter :set_content_type

	  def set_content_type
	    @response.headers["Content-Type"] = "text/html; charset=koi8-r"
	  end
	end


Note that Rails built in Action Cache will break your code if you use it
-
Rails will send the default charset for cached requests, and Page
Caching
may not work either.
C0a32d16cf74103a6b8f31105cb04875?d=identicon&s=25 Mikhail Shevchuk (Guest)
on 2006-01-25 21:29
(Received via mailing list)
On Wed, 25 Jan 2006 12:11:00 -0800
"Tom Fakes" <tom@craz8.com> wrote:

Tom, thanks for the answer, it works very well.

> Note that Rails built in Action Cache will break your code if you use it -
> Rails will send the default charset for cached requests, and Page Caching
> may not work either.
I don't use caching at this moment, but I can't understand why caching
will break it?
This topic is locked and can not be replied to.