palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Using bundle exec puma instead of rails server fails to load Railtie #84

Closed fractaledmind closed 2 years ago

fractaledmind commented 3 years ago

At this line the Railtie is conditionally loaded depending on whether or not ::Rails::VERSION is defined: https://github.com/palkan/anyway_config/blob/f474eaa77d0a342d47f960e40e70e1e6ac964f2e/lib/anyway_config.rb#L39

However, when a Rails app used bundle exec puma to start its webserver instead of bundle exec rails server, ::Rails is not defined at the point that this code is called (in my case I have an /initializers/anyway_config.rb file that is doing minimal configuration, like adding "staging" to known_environments. And I get this error:

 Unable to load application: NoMethodError: undefined method `anyway_config' for #<Rails::Application::Configuration:0x00007fc384baef60>

I have manually debugged and confirmed that the problem is that ::Rails is not defined and that if I run rails server it is defined.

For now, I have worked around this by simply manually calling require "anyway/rails" in my initializer, but this doesn't feel right.

palkan commented 3 years ago

Which version of anyway_config / Rails / Puma do you use?

I tried to reproduce it here: https://github.com/anycable/anycable_rails_demo/tree/try/anyway_config_84 ; bundle exec puma works fine.

fractaledmind commented 3 years ago
anyway_config (2.1.0)
rails (6.1.3.2)
puma (5.3.2)
palkan commented 3 years ago

Is there any third-party gem using anyway_config? That could make it load before Rails (e.g., some puma plugin?).

The only way to check this is to add a breakpoint (or binding.pry) to anyway_config/lib/anyway_config.rb and see what calls it.

palkan commented 2 years ago

Closed as stale