Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle who care about creating, delivering, and maintaining software responsibly. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

Configuration data like this should always be stored in a configuration file. I have the below line in all my rails applications:

# config/application.rb
config.app_config = Rails.application.config_for(:app_config)

You can read more about it here: http://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.