I've done an helper for nested resource's urls
# app/urls/url.rb
module Url; end
Then
# app/urls/base.rb
module Url
class Base
# common code
end
end
When I try to inherit from Url::Base
, a LoadError
arise:
Unable to autoload constant Base, expected xxx/app/urls/base.rb to define it
I've debugged it a little, the file is correctly sourced and the class loaded, but the check is bugged. The error seems to born in ActiveSupport::Dependencies#const_missing
, when it pass Object
as from_mod
(<- this the variable that is expected to include the constant), instead of Url
.
Try this:
Url::Base # Raise LoadError
Url::Base # Works!
I can't still understand why const_missing
trigger on Object
instead of Url
... Some help? What I'm doing wrong?
EDIT
Ok, with more digging, I've understand what's going on. Rails search for a file's path like namespace/class_name.rb
in PATH
; if this file doesn't exists, it try to load the constant in the parent's module (or class), and that's why it will recurse with form_model = Object
.