Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring the environment name in Rails #356

Merged
merged 5 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ which will generate customizable config file `config/initializers/config.rb` and

You can now edit them to adjust to your needs.

> Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`.

### Installing on Padrino

Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`
Expand Down
3 changes: 2 additions & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Config
overwrite_arrays: true,
merge_hash_arrays: false,
validation_contract: nil,
evaluate_erb_in_yaml: true
evaluate_erb_in_yaml: true,
environment: nil
)

def self.setup
Expand Down
2 changes: 1 addition & 1 deletion lib/config/integrations/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def preload

# Parse the settings before any of the initializers
Config.load_and_set_settings(
Config.setting_files(::Rails.root.join('config'), ::Rails.env)
Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
)
end

Expand Down
5 changes: 5 additions & 0 deletions lib/generators/config/templates/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#
# config.overwrite_arrays = true

# Defines current environment, affecting which settings file will be loaded.
# Default: `Rails.env`
#
# config.environment = ENV.fetch('ENVIRONMENT', :development)

# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false
Expand Down