I can't say for sure that this is the problem in Rails, but my guess is that it's not far off the mark. The "fix" at the end may not be easily applied in the case of a Rails app.
First, a directory listing:
> ls -R
.:
bar_then_foo.rb bar_then_foo2.rb foo_then_bar.rb lib_foo lib_fubar
./lib_foo:
helper.rb
./lib_fubar:
helper.rb
The helper modules:
> cat lib_foo/helper.rb
module Helper
def foo
puts "foo"
end
def bar
puts "bar"
end
end
> cat lib_fubar/helper.rb
module Helper
def foo
puts "foo-bar"
end
end
The Ruby code:
> cat bar_then_foo.rb
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_fubar'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_foo'
require 'helper'
class FoobieDoo
include Helper
end
f = FoobieDoo.new
f.foo
f.bar
> cat foo_then_bar.rb
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_foo'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_fubar'
require 'helper'
class FoobieDoo
include Helper
end
f = FoobieDoo.new
f.foo
f.bar
And some output:
> ruby bar_then_foo.rb
foo
bar
> ruby foo_then_bar.rb
foo-bar
foo_then_bar.rb:12: undefined method 'bar' for #<FoobieDoo:0x1042e93c> (NoMethodError)
So Ruby is searching $LOAD_PATH from the end and stops as soon as it finds a match.
Let's try something else:
> cat bar_then_foo2.rb
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_fubar'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib_foo'
require 'helper'
load "lib_fubar/helper.rb"
class FoobieDoo
include Helper
end
f = FoobieDoo.new
f.foo
f.bar
> ruby bar_then_foo2.rb
foo-bar
bar
Desired result?
Maybe you can modify app/helpers/application_helper.rb
to search for other application_helper.rb files in the LOAD_PATH and load them?