Extension Tip: Using Migrations for your Configuration

Spree comes with all sorts of default configurations that you will likely want to customize. Many of these values can be changed now through admin screens (those that can’t be changed will be able to shortly once those screens are written.) Once a preference is changed from its default, the value is stored in the database.

It is possible to use a migration to setup these preferences so that you can set the preferences of your site automatically. This is handy when migrating a new series of configurations from a tested development environment to production. You no longer have to remember to manually change these settings, just run the migrations like normal.

For example, the default country in Spree is United States. If you wanted the default country to be Ireland you could add the following to your site extension:


class AddCustomConfigurations < ActiveRecord::Migration
  def self.up
    Spree::Config.set(:default_country_id => 96)
  end

  def self.down
  end
end
blog comments powered by Disqus

This project is maintained by a core team of developers and is freely available for commercial use under the terms of the New BSD License.

Spree, Spree Commerce and the Spree logo are all trademarks of Spree Commerce, Inc.