Why is there not a way to set a config option that applies to all environments? #5950
AlvesJorge
started this conversation in
General
Replies: 1 comment 1 reply
-
Hey, good question. The general practice in the Rails ecosystem is to use YAML anchors and aliases for this sort of thing. Here's an example: ---
defaults:
options: &default-options
raise_not_found_error: false
development:
clients:
default:
uri: <%= ENV['MONGODB_URI'] %>
options: *default-options
production:
clients:
default:
uri: <%= ENV['PRODUCTION_MONGODB_URI'] %>
options:
<<: *default-options
log_level: :info In the example above, the development options uses the default options directly ( The general syntax here uses an ampersand followed by an identifier to "name" a hash. Then, you reference that named hash with an asterisk followed by that identifier. named_hash: &some-identifier
a: 1
b: 2
c: 3
copied_hash: *some-identifier
extended_hash:
<<: *some-identifier
b: 3
d: 5 I hope that helps. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Instead of
we could write:
It's such an obvious feature that it must have been thought about at some point, I'm wondering why it was never integrated.
Beta Was this translation helpful? Give feedback.
All reactions