GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
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
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.
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.)