Rails 4.1 cannot automatically load a class with names

I made a helper for subresource 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 occurs LoadError:

Unable to autoload constant Base, expected xxx/app/urls/base.rb to define it

I debugged it a bit, the file was loaded correctly, and the class was loaded, but the check is listened to. It seems that an error occurred in ActiveSupport::Dependencies#const_missingwhen it passed Objectas from_mod(<is a variable that should include a constant) instead Url.
Try the following:

Url::Base # Raise LoadError
Url::Base # Works!

I can’t understand why the const_missingtrigger is on Objectinstead Url... Some help? What am I doing wrong?


EDIT

, , , . Rails , namespace/class_name.rb PATH; , ( ), form_model = Object.

+4
1

, , , . Rails , namespace/class_name.rb PATH; , ( ), form_model = Object.

0

Source: https://habr.com/ru/post/1543793/


All Articles