I have an external ecommerce link that varies based based on environment (testing and production systems).
Where should it go in Rails?
Possibilities include:
- a conditional directly in the template, on the button (not a good solution, IMO)
- database (though there's no model for this so it would be a specific case possibly over-generalized)
- application.rb (which I believe is not recommended for this purpose)
- environment-specific application configs
- initializer
- view helper
- YAML file
- (external) environment variable
- etc.
Where would this typically go in Rails?
Some of these keep the template clean, but put a very specific case far away from the place it's used.
Best Answer
Configuration data like this should always be stored in a configuration file. I have the below line in all my rails applications:
You can read more about it here: http://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for