Hello,
After porting some old PHP scripts to Ruby, I'm now having strange
problems with the Ruby 'require' and 'include' mechanisms under
Apache/1.3.28, mod_ruby/1.2.4 and ruby/1.8:
We run several virtual hosts on one machine, each has a structure like this:
file: /rb/tools.rb
module name_of_host # to avoid namespace collisions
def a ()
# ...
end
end
file: /subdir/rb/tools.rb
module name_of_host_subdir
require '../rb/tools.rb'
include name_of_host
def b ()
# ...
end
end
file: /subdir/language/index.rhtml
<%
require '../rb/tools.rb'
include name_of_host_subdir
a()
b()
%>
I get errors like this on Apache restart:
/.../subdir/language/index.rhtml:3: warning: main#include in the wrapped
load is effective only for toplevel
And then HTTP requests produce errors like this:
/.../subdir/language/index.rhtml:3: uninitialized constant
#<Module:0x40560f5c>::name_of_host_subdir (NameError)
from (eval):117
from /.../eruby-run.rb:116:in `eval_string_wrap'
from /.../eruby-run.rb:116:in `run'
from /.../eruby-run.rb:72:in `handler'
/.../subdir/language/index.rhtml:4: undefined method `a' for main:Object
(NoMethodError)
from (eval):117
from /.../eruby-run.rb:116:in `eval_string_wrap'
from /.../eruby-run.rb:116:in `run'
from /.../eruby-run.rb:72:in `handler'
I know that my problem is closely related to this
<http://lists.modruby.net/ml/archive/modruby/200404.month/1161.html>,
and I've tried the suggested patch to Ruby eval.c from Shugo
<http://lists.modruby.net/ml/archive/modruby/200404.month/1162.html>,
but it didn't solve the problem.
Here are the relevant entries in httpd.conf:
LoadModule ruby_module libexec/mod_ruby.so
AddModule mod_ruby.c
<IfModule mod_ruby.c>
RubyRequire apache/ruby-run
RubyRequire apache/eruby-run
RubySafeLevel 2
RubyTimeOut 60
<Files *.rbx>
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
</Files>
<Files *.rhtml>
SetHandler ruby-object
RubyHandler Apache::ERubyRun.instance
</Files>
</IfModule>
Thanks in advance for any helpful information.
Simon