# How to define content charset?

**URL:** <https://www.ruby-forum.com/t/how-to-define-content-charset/53120>\
**Category:** Rails\
**Created:** [January 25, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/how-to-define-content-charset/53120 "2006-01-25T21:02:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stwoland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@stwoland](https://www.ruby-forum.com/u/stwoland)\
**Post date:** [January 25, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/how-to-define-content-charset/53120/1 "2006-01-25T21:02:56Z")

</div>

I tried to define koi8-r charset in app/views/layouts/ like this:

 Cpu: \<%= controller.action\_name %\> \<%= stylesheet\_link\_tag 'scaffold' %\>

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?

---

<div class="post-metadata">

**Author:** ![stwoland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@stwoland](https://www.ruby-forum.com/u/stwoland)\
**Post date:** [January 25, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/how-to-define-content-charset/53120/2 "2006-01-25T21:14:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stwoland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@stwoland](https://www.ruby-forum.com/u/stwoland)\
**Post date:** [January 25, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/how-to-define-content-charset/53120/3 "2006-01-25T21:29:30Z")

</div>

On Wed, 25 Jan 2006 12:11:00 -0800  
“Tom F.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?
