Answer the question
In order to leave comments, you need to log in
What can be done with /lib autoloading?
Some strange behavior of rails.
There is a route
namespace :api do
namespace :v1 do
get 'roistat/calls', to: 'roistat#calls'
end
end
class Api::V1::RoistatController < ActionController::Base
def calls
render :ok
end
end
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'
Answer the question
In order to leave comments, you need to log in
Some bug with autoloading modules from /lib (like here https://github.com/thoughtbot/factory_bot/issues/670)
The easiest way was to rename /lib/roistat/api.rb to /lib/roistat/client. rb
Check if you have the same module and class names, it's possible that rails doesn't resolve dependencies correctly.
And I'd rather structure
module Api
module V1
class RoistatController < ActionController::Base
end
end
end
I'm sorry, but wouldn't it be better to do:
scope :api do
namespace :v1 do
get 'roistat/calls', to: 'roistat#calls'
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question