Brice Sanchez
Brice Sanchez
Senior web developer in Québec city (Canada). I create web applications that help companies to propel their business model.
· Less than 1 min read

5 easy steps to use Refinery CMS and Spree e-commerce on the same Ruby on Rails application

In this guide we will learn how to use Refinery CMS and Spree e-commerce on the same Ruby on Rails application with few easy steps:

1.Generate the Ruby on Rails application 2.Install Spree 3.1.0 3.Install Refinery CMS 3.0.0 4.Mount Spree before Refinery 5.Enjoy your new Spree-Refinery app!

All steps explained in this guide are summarized in the demo app available on Github: https://github.com/refinerycms-contrib/spree-refinery-demo

1. Generate the Ruby on Rails application

This guide required rails (~> 4.2.7)

rails _4.2.7_ new spree-refinery

2. Install Spree 3.1.0

Add Spree gems to your Gemfile:

# Gemfile
[...]
gem 'spree', '~> 3.1.0'
gem 'spree_auth_devise', '~> 3.1.0'
gem 'spree_gateway', '~> 3.1.0'

Run bundle install

Use the install generators to set up Spree:

rails g spree:install --user_class=Spree::User
rails g spree:auth:install
rails g spree_gateway:install

3. Install Refinery CMS 3.0.0

In order to be able to share the authentication between Spree and Refinery CMS, we will use the Spree Refinery Authentication extension available on Github: https://github.com/refinerycms-contrib/spree-refinery-authentication

If you use Solidus E-commerce, you can also use the Solidus Refinery Authentication extension available on Github: https://github.com/refinerycms-contrib/solidus-refinery-authentication

Add Refinery gems to your Gemfile:

# Gemfile
[...]
gem 'refinerycms', '~> 3.0.0'
gem 'spree-refinerycms-authentication', github: 'refinerycms-contrib/spree-refinery-authentication', branch: '3-0-stable'

Run bundle install

In the db/seed.rb file, comment Spree seeds because Spree load seeds only on database creation while Refinery CMS loads seeds on each extension installation with the command rake db:seed.

# db/seeds.rb
[...]
# Spree::Core::Engine.load_seed if defined?(Spree::Core)
# Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

Commenting Spree seeds also fix this error:

[...]
ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
[...]

Now you can use the install generator to set up Refinery:

rails generate refinery:cms --fresh-installation

4. Mount Spree before Refinery

Modify the config/routes.rb file in order to be sure you mount Spree before Refinery:

Rails.application.routes.draw do
  root :to => "refinery/pages#home"
  mount Spree::Core::Engine, :at => '/shop'
  mount Refinery::Core::Engine, at: '/'
end

5. Enjoy your new Spree-Refinery app!

You can now start the rails server and enjoy your app:

rails server
Brice Sanchez
Hey! I'm Brice Senior Web Developer in Québec City (Canada)
who love Ruby, Ruby on Rails and Reactive technologies.
I create web applications that help companies to propel their business model.