Search code examples
ruby-on-railsruby-on-rails-5

Rails `config_for` returning an empty hash


I saw this question yet the solution did not work for me. As per the rails docs, I've taken the following steps:

I've created a file config/benchmarks.yml, with the following content:

Test: "This"

I also added config.benchmarks = config_for(:benchmarks) in the config/application.rb file.

I also added the path to config/spring.rb yet when I go to the console and enter Rails.application.config_for(:benchmarks) it returns an empty hash.

What am I missing here? I'm running Rails 5.2.1.


Solution

  • No need to touch config/spring.rb file. Just make sure you are passing as like in sample below.

    # config/benchmarks.yml
    development:
      test: test
    
    #application.rb
    config.benchmarks = config_for(:benchmarks)
    
    #rails console
    Rails.application.config_for(:benchmarks)
    
    => {
         "test" => "test"
       }