Skip to content

ENV variables not loaded with config #321

@deepakmahakale

Description

@deepakmahakale

I followed this but I am unable to access the environment variable with Settings

config.rb

Config.setup do |config|
  config.use_env = true
  config.env_prefix = 'SETTINGS'
  config.env_separator = '__'
  config.env_converter = :downcase
  config.env_parse_values = true
end
SETTINGS__SECTION__SERVER_SIZE=1 SETTINGS__SECTION__SERVER=google.com SETTINGS__SECTION__SSL_ENABLED=false rails c
Settings.section.server_size # => nil
Settings.section.server      # => nil
Settings.section.ssl_enabled # => nil

# They are accessible this way
ENV['SETTINGS__SECTION__SERVER_SIZE'] #=> "1"
ENV['SETTINGS__SECTION__SERVER']      #=> "google.com"
ENV['SETTINGS__SECTION__SSL_ENABLED'] #=> "false"
  • ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-darwin20]
  • rails (6.1.6)
  • config (4.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions