Hi there,
First off, I'm quite new to web programming and Sinatra, so it's
probably me who's doing something wrong.
Here's my problem: When I have a view which in turn renders another
view (a partial) and this second view contains a special character
like ä somewhere (even in a HTML comment!), Sinatra complains with
this error:
Encoding::CompatibilityError at /
incompatible character encodings: US-ASCII and ASCII-8BIT
My directory structure looks like this (all files are encoded as
UTF-8):
/
- my_app.rb
views/
- main.rhtml
- _part.rhtml
Here's my_app.rb:
====================================
#!/usr/bin/env ruby
#Encoding: UTF-8
require "erb"
require "sinatra/base"
class MyApp < Sinatra::Base
set :app_file, __FILE__
set :root, File.dirname(__FILE__)
configure :development do
enable :logging
enable :dump_errors
set :bind, "localhost"
end
get "/" do
erb :main
end
end
MyApp.run! :host => "localhost", :port => 3000
====================================
main.rhtml:
====================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Test</title>
</head>
<body>
<%= erb :_part %>
<p>Some text with special char ä here</p>
</body>
</html>
====================================
_part.rhtml:
====================================
<p>ä</p>
====================================
(I invoke the application by "ruby my_app.rb")
The special character in main.rhtml always renders fine ("always"
means, if I don't render the partial).
ruby -v: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
Sinatra version: 1.1.0
OS: Ubuntu 10.10 Maverick Meerkat
Here's the full console output Sinatra produces when just opening
http://localhost:3000 in Firefox:
http://pastie.org/1308841
What's wrong here?
Valete,
Marvin