Rails beginner
Rails beginner

Reputation: 14504

How do I change my default charset from ANSI to Unicode in my project?

How do I change my default charset from ANSI to Unicode in my project? When I write special characters as Æ Ø Å in my view that is ANSI it renders a error. But if I change the file to UTF-8 encoding it renders the special characters without a error. Should I then change all my view files from ANSI encoding to UTF-8 ?

Upvotes: 0

Views: 658

Answers (1)

makaroni4
makaroni4

Reputation: 2281

Here is some rails magic - add this comment to your .rb file:

# coding: utf-8

and it should work)

You also can use Iconv class to convert your string to UTF-8 like this:

require 'iconv'
ic = Iconv.new('WINDOWS-1251','UTF-8')
new_string = ic.iconv(old_string)

Upvotes: 1

Related Questions