如何获得需要gem正常运行的Ruby CGI程序?

时间:2010-09-23 04:07:11

标签: ruby apache rubygems cgi

我已将Apache安装配置为运行Ruby CGI脚本。我现在正在尝试运行一个需要gem的简单Ruby CGI脚本。

当我从命令行运行此脚本时,它会正确输出。但是,当我将其称为Apache CGI脚本时,它会生成Apache 内部服务器错误。脚本如下所示:

#!/Ruby/bin/ruby

require 'RedCloth'  # <-- This is the gem

puts "Content-type: text/html"
puts 
puts
puts "<html>"
puts "<head>"
puts "</head>"
puts "<body>"
puts "I want to call a gem."
puts "</body>"
puts "</html>"

Apache错误日志显示以下行:

C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:56:in `join': can't convert nil into String (TypeError)
[error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:56:in `<class:ConfigFile>'
[error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:28:in `<top (required)>'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:29:in `require'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:29:in `require'
[error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems.rb:1110:in `<top (required)>'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:29:in `require'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:29:in `require'
[error] [client 127.0.0.1] \tfrom <internal:gem_prelude>:167:in `load_full_rubygems_library'
[error] [client 127.0.0.1] \tfrom <internal:gem_prelude>:217:in `try_activate'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:32:in `rescue in require'
[error] [client 127.0.0.1] \tfrom <internal:lib/rubygems/custom_require>:29:in `require'
[error] [client 127.0.0.1] \tfrom C:/Apache/Apache2.2/cgi-bin/cgitest.rb:3:in `<main>'

当我不包含require 'RedCloth'行时,Apache执行我的cgi脚本就好了。

有没有明显的我在这里失踪?事实上,你甚至可以执行一个需要宝石的Ruby CGI脚本吗?任何见解将不胜感激。

谢谢, 莫里斯

1 个答案:

答案 0 :(得分:2)

你试试这个吗?

require 'rubygems'
require 'RedCloth'  # <-- This is the gem