我如何获得一个需要宝石才能正常运行Ruby的CGI程序? [英] How do I get a Ruby CGI program that requires a gem to run properly?

查看:214
本文介绍了我如何获得一个需要宝石才能正常运行Ruby的CGI程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置我的Apache安装运行Ruby CGI脚本。现在我想运行需要一个瑰宝一个简单的Ruby CGI脚本。

I have configured my Apache installation to run Ruby CGI scripts. I am now trying to run a simple Ruby CGI script that requires a gem.

当我运行在命令行这个脚本,它正确输出。但是,当我把它作为Apache CGI脚本,它会生成一个Apache的内部服务器错误即可。该脚本是这样的:

When I run this script from the command line, it outputs correctly. But when I call it as an Apache CGI script, it generates an Apache Internal Server Error. The script looks like this:

#!/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的错误日志显示这些行:

The Apache error log shows these lines:

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>'

当我不包括要求'RedCloth行,Apache的执行我的CGI脚本就好了。

When I don't include the require 'RedCloth' line, Apache executes my cgi script just fine.

是否有明显的成才说我在这里丢失?可你,其实,即使是执行需要一个宝石Ruby的CGI脚本?任何见解将大大AP preciated。

Is there someting obvious that I'm missing here? Can you, in fact, even execute a Ruby CGI script that requires a gem? Any insights would be greatly appreciated.

谢谢,
莫里斯

Thanks, Maurice

推荐答案

你有没有尝试这个?

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

这篇关于我如何获得一个需要宝石才能正常运行Ruby的CGI程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆