Fellow Stranger
Fellow Stranger

Reputation: 34113

How to define application configurations in Rails 5?

I've normally put settings like the below in config/application.rb

config.generators.stylesheets = false
config.time_zone = 'Berlin'

But in Rails 5 the message below is found in config/application.rb

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

What does this mean? Am I supposed to add an initializer-file for every config setting? And in that case, what should such a file contain?

Upvotes: 1

Views: 1384

Answers (1)

oreoluwa
oreoluwa

Reputation: 5633

You should still be able to put the configuration in your config/application.rb, however the message is informing you that your environment specific configurations take precedence over those specified there, so if you have another configuration overriding any of such values in your config/environments those in the environment specific would be used.

If you're using the initializers approach, in your config/initializers/stylesheet_generator.rb, you'd have:

Rails.application.config.generators.stylesheets = false

and in your config/initializers/time_zone.rb, you'd have:

Rails.application.config.time_zone = 'Berlin'

Upvotes: 3

Related Questions