Encoding::CompatibilityError with ruby 1.9.3p0 on windows #152

Closed
scriptfans opened this Issue Jul 5, 2012 · 3 comments

Comments

Projects
None yet
3 participants

I use Tilt to handle my erb template which contain some chinese characters, But it was wrong:

Encoding::CompatibilityError in Servicdev::NodesController#show

incompatible character encodings: ASCII-8BIT and UTF-8

my ruby code is:

path = Rails.root.join('templates', "test.erb").to_s template = Tilt.new path template.render

and the test.erb's content is:

<%# 中文注释 %> <tag name="测试" />

I found the template.data.encoding is incorrect (ASCII-8BIT), So I can solve the problem by change the ruby code to:

path = Rails.root.join('templates', "test.erb").to_s template = Tilt.new path template.instance_variable_set(:@default_encoding, 'utf-8') template.render

But is that correct? will have any side effects? I'm not sure. I think this is a Tilt's bug

Collaborator

judofyr commented Jul 31, 2012

Can you try the encodings-branch here and see if that solves the problem?

I found this issue using serve (get-serve.com), encodings branch solved the problem. Would be great to see this in the next release.

Collaborator

judofyr commented Mar 24, 2013

In the latest version of Tilt (1.3.6) you should be able to override the encoding like this:

Tilt.new(path, :default_encoding => 'utf-8')

We're aiming for merging in #175 soon. See the documentation in that pull request for how it will work in the future.

(I'm closing this now since it's been a while. Please re-open this if you need more help for with a workaround for current Tilt. Chime in on #175 if you have concerns about the upcoming encoding support.)

@judofyr judofyr closed this Mar 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment