Skip to content

Instantly share code, notes, and snippets.

@harssh
Created July 28, 2014 14:45
Show Gist options
  • Save harssh/5cce28f2f6095114e857 to your computer and use it in GitHub Desktop.
Save harssh/5cce28f2f6095114e857 to your computer and use it in GitHub Desktop.
Use spree backend only ........

Set up a Spree backend only install

rails new store-backend

Gemfile

gem 'spree_backend', github: 'spree/spree'
gem 'devise'

Install Spree and Devise

rails g spree:install

rails g devise:install    
rails g devise User  
    
bundle exec rake db:migrate  

This should go in your User model

has_and_belongs_to_many :spree_roles

def has_spree_role?(role)
  self.spree_roles.all.include? role
end
  • Generate custom user set up for spree
rails g spree:custom_user User
  • Change Spree.user class to User on initializer spree.rb
Spree.user_class = "User"
  • Add fields to custom user
bundle exec rake db:migrate
  • Remove both all.css and all.js from vendor/assets/javascript|stylesheets/spree/frontend/

Make sure your config/routes.rb look like this

Rails.application.routes.draw do
  root to: "spree/admin/orders#index"
  mount Spree::Core::Engine, :at => '/'

  devise_for :users do
    get '/login', :to => "devise/sessions#new"
    delete '/logout', :to => "devise/sessions#destroy"
  end
end

Point spree_signup_path to login page

# since we don't need signup on a backend install
def spree_signup_path
  main_app.login_path
end

Create admin user via rails console

user = User.create(email: "[email protected]", password: "spree123")
user.spree_roles << Spree::Role.find_or_create_by(name: "admin")

Deface admin layout template to add logout link

Create this file in app/overrides/spree/layouts/admin/inject_login_bar.html.erb.deface

<!-- replace_contents "[data-hook='admin_login_navigation_bar']" -->

<ul id="login-nav" class="inline-menu">
  <li><%= link_to('Edit', main_app.edit_user_registration_path) %></li>
  <li><%= link_to('Logout', main_app.destroy_user_session_path, :method => :delete) %></li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment