What you can do with auto-load /lib?

Some strange behavior rails.
There is a Routh
namespace :api do
 namespace :v1 do
 get 'roistat/calls', to: 'roistat#calls'
end
 end

There is a controller
class Api::V1::RoistatController < ActionController::Base

 def calls
 render :ok
end
end

Kick it and see:
Started GET "/api/v1/roistat/calls" for 127.0.0.1 at 2018-05-18 09:19:54 +0300

LoadError (Unable to autoload constant Api, expected /path/to/project/lib/roistat/api.rb to define it):
 activesupport (4.2.7.1) lib/active_support/dependencies.rb:495:in `load_missing_constant'
 activesupport (4.2.7.1) lib/active_support/dependencies.rb:184:in `const_missing'

It would seem... where does the /lib ?
June 5th 19 at 21:12
3 answers
June 5th 19 at 21:14
Solution
Some bug with autoload modules in /lib (like here https://github.com/thoughtbot/factory_bot/issues/670)
The easiest way was to rename /lib/roistat/api.rb /lib/roistat/client.rb
June 5th 19 at 21:16
Check whether you have same names of modules and classes, it is possible that rails correctly resolves the dependencies.
And I would rather structure
module Api
 module V1
 class RoistatController < ActionController::Base
end
end
end
June 5th 19 at 21:18
I'm sorry, but isn't it better to do:
scope :api do
 namespace :v1 do
 get 'roistat/calls', to: 'roistat#calls'
end
end


PS: and finally I kazhetso that the machinations of the beeches ;)

Find more questions by tags Ruby on Rails