Spree Quickstart

How to quickly get started with Spree on Rails.

    1. MySQL
    2. Rails
      1. Setup the MySQL database
      2. Spree
      3. Remove frontend leftovers

MySQL

Prepare MySQL for the Rails app.

CREATE USER spree_db_user@'localhost' IDENTIFIED BY 'secreto';
GRANT ALL PRIVILEGES ON spree_example_development.* TO spree_db_user@'localhost';
GRANT ALL PRIVILEGES ON spree_example_test.* TO spree_db_user@'localhost';

exit

You can verify that the user was correctly created:

mysql -u spree_db_user -p

Rails

Create the Rails app and enter that folder.

rails new spree-example -d mysql
cd spree-example

Setup the MySQL database

In config/database.yml update the username, password and database name that we just created.

default: &default                                                                
  adapter: mysql2                                                                
  encoding: utf8                                                                 
  pool: 5                                                                        
  username: spree_db_user                                                        
  password: 'secreto' 

development:                                                                     
  <<: *default                                                                   
  database: spree_example_development

test:                                                                            
  <<: *default                                                                   
  database: spree_example_test

Create the database.

rake db:create

At this point we should have an empty Rails app that is able to boot.

rails s
# visit 
# http://localhost:3000/

You'll see the usual:

Welcome aboard You’re riding Ruby on Rails!

Spree

Remember API only.

In Gemfile add

gem 'spree_backend', '3.0.0'
gem 'spree_sample', '3.0.0'
bundle install
rails g spree:install

Edit config/routes so that it looks like this:

  #get "/" => redirect("/admin")
  #get "/login" => redirect("/admin/login")
  root to: "spree/admin/orders#index"
 
  mount Spree::Core::Engine, :at => '/'

In config/initializers/devise.rb add


Setup app.

rake db:migrate
rake db:seed
rake spree_sample:load

All done, run the app:

rails server
# visit

Remove frontend leftovers

rm -r vendor/assets/javascripts/spree/frontend/
rm -r vendor/assets/stylesheets/spree/frontend/