I have a file called frontend_configuration.rb which looks like this:
class FrontEndConfiguration
class << self
attr_accessor :base_url
end
end
In my development config, I have a line:
FrontEndConfiguration.base_url = "http://localhost:4200"
When I try to run my rails server, it gives me an error saying:
uninitialized constant FrontEndConfiguration (NameError)
I am following this Stackoverflow answer here: Rails 3 / Setting Custom Environment Variables
Any ideas why Rails isn't detecting my custom initializer?
I am using Rails 5 API only mode.
Try this.
# config/frontend.yml:
production:
environment: production
base_url: http://your_url
.
.
.
development:
environment: sandbox
base_url: http://your_url
.
.
.
# config/application.rb
module MyApp
class Application < Rails::Application
config.frontend = config_for(:frontend)
end
end
And now,
Rails.configuration.frontend['base_url']
# => production_base_url or development_base_url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With