Rails.application.config_for and Rails.config.x

Hello guys,

I just came across this post http://www.justinweiss.com/blog/2014/08/25/the-lesser-known-features-in-rails-4-dot-2/?utm_source=rubyweekly&utm_medium=email which shows the Rails.application.config_for feature.

What if config.x by default reads the configuration files?

In other words, Rails.config.x.redis.host == Rails.application.config_for(:redis)[“host”].

I don’t think this would be a good idea. IMO doing a config_for(:redis)['host'] is much more clear than doing a config.x.redis.host.

By the way what would that “x” be? Can you think of a good name?

config_for is better because it signals that you are doing non-standard configuration reading (i.e. you are loading a file, not reading directly from the Configuration object). The syntax you are suggesting will require we mess with the method_missing behavior to either read from config hash or read from a YAML file, depending on “x”.

The best name for "x" that I can think of would be "for".

`config.for.redis.host`

Allen Madsen
http://www.allenmadsen.com

So config.for.redis.host vs. config_for(:redis)['host'].

Number 2 is a clear winner for me. Much cleaner, does not require metaprogramming to be implemented (method_missing or define_method) and is much simpler in the implementation.

powii,

config.x is already a rails feature :slight_smile: