Closed nicolas-brousse closed 3 years ago
We do use Rails inflector: https://github.com/palkan/anyway_config/blob/fb2622bf30e61a834567d0945568606b2b34e12a/lib/anyway/rails/settings.rb#L33
Can you show me the full backtrace? I guess, that could happen when you try to load the config class before the inflector initializer is loaded.
@palkan thanks for your answer. I'll have a look on it an may try to create a sample application that have the same issue.
I try to reproduce it on a rails template but I can't reproduce the issue.
In my application, I've the following full backtrace on page loading:
I've the issue on both webpage and console. On webpage it's on a specific page that call Payzen API, and so call config file to get credentials.
I've inspect the code a bit more.
If I'm not wrong, before_configuration
execute code before initializers are loaded. I guess this is done to have access to config file in initializers.
But because of this, config/initializers/inflections.rb
is not loaded yet.
What I've done to try to understand what the code doing is to put a binding.pry
at the end of the following method:
https://github.com/palkan/anyway_config/blob/068fdf1504aa21ee04863a43fa99152c53581753/lib/anyway/rails/settings.rb#L21-L37
And I notice the following:
[4] pry(Anyway::Settings)> @autoloader.autoloads
=> {"/home/user/Projects/rails/config/configs/application_config.rb"=>[Object, :ApplicationConfig],
"/home/user/Projects/rails/config/configs/payzen_api_config.rb"=>[Object, :PayzenApiConfig]
Seems the class name already defined, before inflection initializers loaded.
Thanks for the investigation!
Seems the class name already defined, before inflection initializers loaded.
Yeah, we call loader.setup
before initialization. Since the point of this loader is to configure autoload before initialization, we cannot have an access to initializers here.
I suggest configuring inflections in the very beginning of the application boot process, e.g., in your config/application.rb
:
require_relative "initializers/inflections"
module MyApp
class Application < Rails::Application
# ...
end
end
Added a note to readme: https://github.com/palkan/anyway_config/commit/883c78172823def2bbedd48c8f488e8112199378
@palkan thank you for the support!
What did you do?
I've a config file in Rails application that follow an inflection acronym.
What did you expect to happen?
Code works and load correctly.
What actually happened?
I've got the following error.
Additional context
I suspect eager load not to use rails loader or not the rails inflector. https://github.com/palkan/anyway_config/blob/master/lib/anyway/railtie.rb#L16
Environment
Ruby Version: ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]
Framework Version (Rails, whatever): Rails 6.0.3.7
Anyway Config Version: 2.1.0