Using Spree and Refinery together

The combination of Spree and Refinery is promising for e-commerce sites incorporating some CMS pages. I recently ran through the process of installing both of these engines and configuring them to play nice with each other. You can do this too!

Firstly, a note on versions. For this guide, I’ve use Rails 3.2.3, Spree 1.1rc and Refinery 2.0.2. I’ve used the Spree 1.1rc instead of the stable 1.0.x version because the stable version depends on Rails 3.1 and Refinery 2.0.x expects Rails 3.2. The Spree 1.1rc is Rails 3.2 compatible, so our whole project can happily run on Rails 3.2.

Install Rails

$ rails new spreefinery
Uncomment therubyracer in the Gemfile

Install Spree 1.1rc

$ cd spreefinery
$ spree install --git=git://github.com/spree/spree.git --branch=1-1-stable

Install Refinery

Add to Gemfile: gem 'refinerycms', '~> 2.0.0'
$ bundle install
Comment out the Spree lines in db/seeds.rb to avoid double-seeding Spree
$ rails generate refinery:cms --fresh-installation
Uncomment the Spree lines in db/seeds.rb

Reference: http://refinerycms.com/guides/with-an-existing-rails-app

Patch will_paginate

Refinery uses the will_paginate gem for pagination, while Spree uses Kaminari. Unfortunately, these two gems are incompatible. To work around this, add the following to config/initializers/spreefinery.rb:

if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        alias_method :per, :per_page
        alias_method :num_pages, :total_pages
      end
    end 
  end
end

References:

Configure routes

I wanted my home page and an about page served by Refinery, and the products page served by Spree. To accomplish this:

Mount Spree before Refinery in config/routes.rb
Above both engine mounts, add:
root :to => "refinery/pages#home"

You should now have Spree and Refinery running together. There’s room for some further improvements to this configuration, since Spree and Refinery still use their own authentication systems and layouts, but it should be enough to get started with.

Become so much more better at emacs. Maybe not grammar, though.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Random readings...


     
     
     

    2 Responses to “Using Spree and Refinery together”

    1. Ash Ganatra
      27 September 2012 at 18:15

      Interesting Article! What about authentication is that single sign on or do you have to use 2 logins for each section?

    2. Rohan
      14 December 2012 at 11:56

      This particular approach needs a login for each section, but my friend wrote a gem that accomplishes single sign on: https://github.com/maleko/spree_refinery_auth

    Leave a Reply

    CommentLuv Enabled