I am having a problem using mod_ruby and eruby. I just installed the latest
stable tarballs of each on a Red Hat Linux 8.0 machine, and everything
seemed to be working just fine. In combination with REXML this really seems
to be the ticket for a simple web app I need.
However, now I’m having an intermittent problem. The .rhtml file I am
testing intermittently results in errors such as:
/tmp/Viewer.rhtml.10484.0:79: undefined method create_submit' for #<Object:0x40f3c338> (NoMethodError) from /opt/ictools/ruby/lib/ruby/1.7/apache/eruby-run.rb:113:in
load’
from /opt/ictools/ruby/lib/ruby/1.7/apache/eruby-run.rb:113:in run' from /opt/ictools/ruby/lib/ruby/1.7/apache/eruby-run.rb:78:in
handler’
from ruby:0
I must admit I am a complete newbie at CGI and Apache in general (although
not Ruby). I could be doing something incredibly stupid. I’m still
basically at the playing around stage.
These are the relevant pieces of the code:
… html header stuff
<%
require 'cgi’
require ‘FormHelper’ # a little helper class to generate some common forms
etc I need
include FormHelper
some CGI and form stuff here
create_submit(‘blah’, ‘blah’)
%>
… html footer stuff
Because this error only happens about 1 out of 5 times I am completely
baffled. I’ve configured the browser to not use a cache at all (to try and
eliminate caching effects) yet it still fails in this manner.
I’ve never had Ruby ‘sometimes’ complain about not being able to find a
method. Style aside, what is wrong with the use of include above?
Can anyone help?
Thanks,
Brett Williams
Apache runs several child processes to handle incoming connections. By
default, it runs 5 under low loadings. mod_ruby caches scripts loaded using
‘require’, but the caching is separate for each child process. (Not really
‘caching’, but the actual way it does it is irrelevant.)
What is happening here is, one of your child processes is using and old
version of FormHelper (presumably) which doesn’t contain the create_submit
method. When this particular child process answers your request, it fails.
Any other time, it works.
To force mod_ruby to reload the scripts, either restart Apache and/or use
‘load’ instead of ‘require’ in your script. The latter option will add some
loading overhead (since you no longer have a hot cache) and so once you’re
sure FormHelper isn’t going to change for a while, you can use ‘require’
again to get the benefits of that caching.
Tim Bates
···
On Fri, 7 Mar 2003 2:24 pm, vor_lord@hotmail.com wrote:
require ‘FormHelper’ # a little helper class to generate some common forms
Because this error only happens about 1 out of 5 times I am completely
baffled. I’ve configured the browser to not use a cache at all (to try and
eliminate caching effects) yet it still fails in this manner.
I’ve never had Ruby ‘sometimes’ complain about not being able to find a
method. Style aside, what is wrong with the use of include above?
Can anyone help?
–
tim@bates.id.au
“Tim Bates” tim@bates.id.au wrote in message
news:200303071432.31225.tim@bates.id.au…
[snip]
What is happening here is, one of your child processes is using and old
version of FormHelper (presumably) which doesn’t contain the create_submit
method. When this particular child process answers your request, it fails.
Any other time, it works.
To force mod_ruby to reload the scripts, either restart Apache and/or use
‘load’ instead of ‘require’ in your script. The latter option will add
some
loading overhead (since you no longer have a hot cache) and so once you’re
sure FormHelper isn’t going to change for a while, you can use ‘require’
again to get the benefits of that caching.
Problem solved. Many thanks–dumb mistake by an apache newbie. Now, with
eruby-debug turned on things are going just great!
mod_ruby/eruby/REXML is just a joy to develop in. Thanks to everyone who
works on any of these. REXML has just completely spoiled me–I love the
API.
– Brett Williams