Rails 和 Ruby 1.9 中的无效多字节字符 (US-ASCII)
问题描述:
我使用 Ruby 1.9.1 和 Rails 2.3.4 我的应用程序是处理文本输入
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 = """"
我收到以下错误:
#<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?
有什么想法吗?
答
您是否尝试过在使用非 ASCII 字符的脚本中添加魔法注释?它应该位于脚本之上.
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
它对我很有用.