【问题标题】:Ruby on Rails application won’t start using Passenger when there are non-ASCII characters in the app path当应用程序路径中有非 ASCII 字符时,Ruby on Rails 应用程序不会开始使用Passenger
【发布时间】:2012-04-16 14:23:34
【问题描述】:

我在使用Passenger 运行Ruby on Rails 应用程序时遇到问题。我的应用程序位于 /Users/Glutexo/Práce/Bytek/Bytek 目录中,您可以看到 (á) 中有一个非 ASCII 字符。即使我将它符号链接到另一个目录,例如/Library/WebServer/Documents/Bytek 所有字符都是 US-ASCII,问题仍然存在。

但是当我在所有 US-ASCII 路径中物理创建另一个 Rails 应用程序时,例如 /Users/Glutexo/rails/pokus,它可以工作:应用程序通过Passenger 启动并正常运行。

我在尝试运行位于非 ASCII 路径中的 Rails 应用程序时得到的错误页面如下:

错误信息:

US-ASCII 中的无效字节序列

异常类:

参数错误

回溯:

0 | /Users/Glutexo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/pathname.rb | 45 |在`=~'中

pathname.rb 中提到的那一行在以下函数中:

# 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

有没有人有任何建议,如何说服Passenger 能够在包含非ASCII 字符的路径中运行Ruby on Rails 应用程序?

Rails 是 3.2.2 版,Ruby 是 1.9.3-p125 版,Apache 是 2.2.21 版,Passenger 是 3.0.12 版。

提前感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails deployment passenger non-ascii-characters


    【解决方案1】:

    解决此问题的方法是在您的 rails 应用程序源文件中添加“魔术注释”。例如,在将遇到非 ascii 字符的文件的开头,添加以下内容:

    # encoding: utf-8
    

    有一个有用的 gem 可以帮助你做到这一点:https://github.com/m-ryan/magic_encoding

    为确认此解决方案,我在包含“Práce”的目录中使用 rails 应用程序设置了乘客,但遇到了类似的错误。我在 Rails 应用程序的根目录中运行了 magic_encoding gem 的“magic_encoding”命令。我重新启动了乘客,它似乎已经成功了。希望对您有所帮助!

    另见:invalid multibyte char (US-ASCII) with Rails and Ruby 1.9

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 2017-12-09
      • 1970-01-01
      相关资源
      最近更新 更多