However you cut it, sometimes there are differences between the development and production environments.

For example, if you are integrating your website with PayPal, you probably want your local tests in the development environment to hit https://developer.paypal.com/, and not the main site at https://www.paypal.com/.

In my applications, I always store the URL to the PayPal service in a Setting or Configuration object. This allows me the flexibility of changing the value whenever I need to.

Of course, I use Migrations to generate my tables, or pre-populate them with data. Here is a typical migration:

1
2
3
4
5
6
7
8
9
10
11
12
13
class SetupPaypalConfig < ActiveRecord::Migration
  def self.up
    config = Configuration.find_or_create_by_name('paypal.url')
    config.value = 'https://www.paypal.com/'
    config.save!
  end

  def self.down
    Configuration.find_or_create_by_name('paypal.url').destroy
  end

  class Configuration < ActiveRecord::Base; end
end

Nothing prevents me from keying off RAILS_ENV like this:

1
2
3
4
5
6
7
config.value = case RAILS_ENV
               when 'development'
                 'https://developer.paypal.com/'
               else
                 'https://www.paypal.com/'
               end
config.save!

An alternative would be to store the PayPal URL in a constant, and initialize the constant in config/environments/*.rb. This means much less code. But in my case, I usually have a need for a configuration-like object where admins of the system can change some values.

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives