开发者

How do I get a Ruby CGI program that requires a gem to run properly?

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.

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

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

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

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


Have you try this ?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜