Using a custom config file

(1) Create a file <config_name>.yml in config directory.

(2) Add configuration to the YAML file. You can specify configuration per environment.

default: &default
  config_one: 'config_one'
  config_two: 'config_two'

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default
  config_two: 'config_2' #Override default

(3) Load the configuration file in the application.rb

class Application < Rails::Application
  config.load_defaults 5.1
  config.api_only = true
  config.myappconfig = Rails.application.config_for(:myappconfig)
end

(4) Use the configuration in your code.

myconfig = Rails.configuration.myappconfig['config_two']

AI Summary
Chrome On-device AI 2024-12-06 18:29:55

Share Article