Different data per environment in migrations
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:
Nothing prevents me from keying off RAILS_ENV like this:
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.
Leave a Reply