Discussion:
RailsDispatcher and files in "lib"
Andre Nathan
2007-01-04 02:06:32 UTC
Permalink
Hello

I have Rails running under mod_ruby, with the RailsDispatcher. I've come
into a problem while trying to run ozimodo (ozimodo.rubyforge.org).

Basically, it comes down to the fact that apparently libraries stored in
the "lib" dir of a Rails application are not being correctly required by
RailsDispatcher.

The error I'm getting is the following:

[Wed Jan 03 23:53:27 2007] [error]
mod_ruby: /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:262:in
`eval': /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:441:in
`const_missing': uninitialized constant Ozimodo (NameError)

The "Ozimodo" module is defined in lib/ozimodo/type_parser.rb. In the
RailsDispatcher code, the "require_or_load" method from ActiveSupport's
Dependencies module is overwritten to account for the mod_ruby
environment. The argument to this method is a filename to be loaded, and
in this case, it's being passed the string
"apache/rails_dispatcher/current_module/ozimodo". The method
"require_file" ends up being called, which appends ".rb" to the
filename, and tries to load it (it fails, because the file doesn't
exist) and then tries to require it, which also fails.

I'm not sure what would be the correct solution, but it seems that if
the argument given to require_or_load is a directory, the method should
search for the .rb files inside it, and then try to load/require them.

Does that sound reasonable? Anyone else had problems with this?

Thanks in advance,
Andre
Andre Nathan
2007-01-04 18:27:20 UTC
Permalink
Post by Andre Nathan
[Wed Jan 03 23:53:27 2007] [error]
mod_ruby: /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:262:in
`eval': /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:441:in
`const_missing': uninitialized constant Ozimodo (NameError)
In environment.rb, ozimodo does this:

Dir[File.join(THEME_DIR, 'tumble', 'types', '*')].each do |f|
TYPES[File.basename(f).sub(/^_/,'').sub('.rhtml','')] =
Ozimodo::TypeParser.parse_file(f)
end

and that's where the error comes from. With the patch attached, I
managed to make the Ozimodo module to be found, but now it can't see the
TypeParser class that's defined inside it:

[Thu Jan 04 15:54:18 2007] [error]
mod_ruby: /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:262:in
`eval': /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:459:in
`const_missing': uninitialized constant TypeParser (NameError)

What happens is the following: in the "Module#const_missing" definition
in rails-dispatcher.rb, there is the following code:

require_dependency(file_path)
if env.module.const_defined?(class_id)
return env.module.const_get(class_id)
else
raise LoadError
end

file_path is "ozimodo/type_parser", and class_id is :TypeParser. The
call to require_dependency works (as "lib/ozimodo/type_parser.rb"
exists) and the file is loaded, but the TypeParser constant is not
defined in env.module (Apache::RailsDispatcher::CURRENT_MODULE), but in
Apache::RailsDispatcher::CURRENT_MODULE::Ozimodo instead. I still
couldn't figure out the correct way to make it find the constants
recusively in submodules of env.module... I'll see if I get some idea
from the rails source now...

Does anyone know if Shugo reads this list? Is there any working
interface for bug reports or for sending patches?

Thanks,
Andre
Andre Nathan
2007-01-05 13:20:10 UTC
Permalink
OK, I got it to work. I'm attaching the current patch in case someone
else ends up having this problem. I'll try to contact Shugo to ask him
if this is the correct fix for the problem.

Andre
Post by Andre Nathan
Post by Andre Nathan
[Wed Jan 03 23:53:27 2007] [error]
mod_ruby: /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:262:in
`eval': /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:441:in
`const_missing': uninitialized constant Ozimodo (NameError)
Dir[File.join(THEME_DIR, 'tumble', 'types', '*')].each do |f|
TYPES[File.basename(f).sub(/^_/,'').sub('.rhtml','')] =
Ozimodo::TypeParser.parse_file(f)
end
and that's where the error comes from. With the patch attached, I
managed to make the Ozimodo module to be found, but now it can't see the
[Thu Jan 04 15:54:18 2007] [error]
mod_ruby: /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:262:in
`eval': /usr/lib/ruby/1.8/apache/rails-dispatcher.rb:459:in
`const_missing': uninitialized constant TypeParser (NameError)
What happens is the following: in the "Module#const_missing" definition
require_dependency(file_path)
if env.module.const_defined?(class_id)
return env.module.const_get(class_id)
else
raise LoadError
end
file_path is "ozimodo/type_parser", and class_id is :TypeParser. The
call to require_dependency works (as "lib/ozimodo/type_parser.rb"
exists) and the file is loaded, but the TypeParser constant is not
defined in env.module (Apache::RailsDispatcher::CURRENT_MODULE), but in
Apache::RailsDispatcher::CURRENT_MODULE::Ozimodo instead. I still
couldn't figure out the correct way to make it find the constants
recusively in submodules of env.module... I'll see if I get some idea
from the rails source now...
Does anyone know if Shugo reads this list? Is there any working
interface for bug reports or for sending patches?
Thanks,
Andre
Shugo Maeda
2007-01-23 08:27:40 UTC
Permalink
Hi, sorry to be late.
Post by Andre Nathan
OK, I got it to work. I'm attaching the current patch in case someone
else ends up having this problem. I'll try to contact Shugo to ask him
if this is the correct fix for the problem.
I commited your patch to SVN. Thanks!

Shugo
Andre Nathan
2007-01-23 11:37:41 UTC
Permalink
Post by Shugo Maeda
I commited your patch to SVN. Thanks!
Thank you!

This patch doesn't seem to be enough though, at least for recent
versions of rails... I couldn't make either typo or rforum run, and
wasn't able to find out what the problem was after a lot of
debugging. :/

Best regards,
Andre

Loading...