Ruby-on-rails – invalid multibyte char (US-ASCII) with Rails and Ruby 1.9

ruby-1.9ruby-on-rails

I'm using Ruby 1.9.1 with Rails 2.3.4 My application is to handle text input

If I try something like (the inside quotation marks look different)

text = "”“"

I get the following error:

#<SyntaxError: /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII)
/Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII)
/Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: syntax error, unexpected $end, expecting keyword_end

I need to user those quotation marks as users might input them and I have to account for that?

Any ideas?

Best Answer

Have you tried adding a magic comment in the script where you use non-ASCII chars? It should go on top of the script.

#!/bin/env ruby
# encoding: utf-8

It worked for me like a charm.

Related Topic