问题描述
我在运行使用Passenger的Ruby on Rails应用程序时遇到问题。我的应用程序驻留在/ Users / Glutexo /Práce/ Bytek / Bytek目录中,您可以看到(á)中有一个非ASCII字符。即使我将其链接到另一个目录,例如/ Library / WebServer / Documents / Bytek,其中所有字符都是US-ASCII,问题依然存在。
I have a problem running a Ruby on Rails application using Passenger. My application resides in the /Users/Glutexo/Práce/Bytek/Bytek directory, which you can see has a non-ASCII character in in (á). Even when I symlink it into another directory, e.g. /Library/WebServer/Documents/Bytek with all characters being US-ASCII, the problem is still there.
但是当我以所有US-ASCII路径,如/ Users / Glutexo / rails / pokus,它的作用:应用程序通过Passenger启动并正常运行。
But when I create another Rails application physically in all US-ASCII path, like /Users/Glutexo/rails/pokus, it works: The application starts and runs normally through Passenger.
尝试运行Rails时遇到的错误页面驻留在非ASCII路径中的应用程序说:
The error page I get when trying to run a Rails application residing in non-ASCII path says the following:
US-ASCII中的无效字节序列
invalid byte sequence in US-ASCII
异常类:
ArgumentError
ArgumentError
追溯:
0 | /Users/Glutexo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/pathname.rb | 45 |在`=〜'
0 | /Users/Glutexo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/pathname.rb | 45 | in `=~'
提到的pathname.rb中的行位于以下函数中:
The line in pathname.rb mentioned is in the following function:
# chop_basename(path) -> [pre-basename, basename] or nil
def chop_basename(path)
base = File.basename(path)
if /\A#{SEPARATOR_PAT}?\z/o =~ base # This is the line no. 45
return nil
else
return path[0, path.rindex(base)], base
end
end
private :chop_basename
非ASCII字符?
Rails是3.2.2版本,Ruby是1.9.3-p125版本,Apache是版本2.2.21,Passenger是3.0.12版本。
Rails is version 3.2.2, Ruby is version 1.9.3-p125, Apache is version 2.2.21, Passenger is version 3.0.12.
提前感谢任何帮助!
推荐答案
这个问题是为您的rails应用程序源文件添加一个魔术评论。例如,在将要遇到非ASCII字符的文件的开头,添加以下内容:
The solution to this problem is to add a 'magic comment' to your rails app source files. For example, at the beginning of a file that will encounter a non-ascii character, add the following:
# encoding: utf-8
有一个有用的gem可以帮助你这样做:
There's a useful gem out there to help you do this: https://github.com/m-ryan/magic_encoding
为了确认这个解决方案,我在一个包含Práce的目录中设置了一个rails应用程序的乘客,并给你一个类似的错误。我在我的rails应用程序的根目录下运行magic_encoding gem的magic_encoding命令。我重新启动了乘客,似乎已经完成了诀窍。希望有帮助!
To confirm this solution, I setup passenger with a rails app in a directory containing 'Práce' and got a similar error to you. I ran the magic_encoding gem's 'magic_encoding' command in the root of my rails app. I restarted passenger and it seems to have done the trick. Hope that helps!
另请参见:
这篇关于当应用程序路径中有非ASCII字符时,Ruby on Rails应用程序将无法开始使用Passenger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!