ruby-on-railsspreespree-auth-devisealchemy-cmsalchemy-spree

How to add alchemy to existing spree project


I have an existing Spree project that is functioning. I'm not try to include Alchemy CMS in the project. I followed the guide on the Github Repo. The only exception is that I skipped the auth step because I already have spree_auth_devise configured. When trying to install Alchemy, bundle exec rake alchemy:install. I get the error below.

error

rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'alchemy_spree'.
/Users/atbyrd/dev/distinct-existence/config/application.rb:7:in `<top (required)>'
/Users/atbyrd/dev/distinct-existence/Rakefile:4:in `require'
/Users/atbyrd/dev/distinct-existence/Rakefile:4:in `<top (required)>'
NameError: uninitialized constant Alchemy::AuthEngine
/Users/atbyrd/dev/distinct-existence/config/application.rb:7:in `<top (required)>'
/Users/atbyrd/dev/distinct-existence/Rakefile:4:in `require'
/Users/atbyrd/dev/distinct-existence/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

Gemfile

ruby '2.2.4'
source 'https://rubygems.org'

gem 'rails', '4.2.5'
gem 'pg', '~> 0.15'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'active_model_serializers'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spree', github: 'spree/spree'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'
gem 'puma'
gem 'paperclip'
gem 'aws-sdk', '< 2.0'
gem 'delayed_job_active_record'

gem 'alchemy_spree'
gem 'alchemy_cms'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

config/initializers/alchemy.rb

# Tell Alchemy to use the Spree::User class
Alchemy.user_class_name = 'Spree::User'
Alchemy.current_user_method = :spree_current_user

# Load the Spree.user_class decorator for Alchemy roles
require 'alchemy/spree/spree_user_decorator'

# Include the Spree controller helpers to render the
# alchemy pages within the default Spree layout
Alchemy::BaseHelper.send :include, Spree::BaseHelper
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Common
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Store

Solution

  • Looks like outdated gem versions. Which version of Spree are you using? Please check your Gemfile.lock. If it's 3.x then please try to use the GitHub version of this gem by using gem 'alchemy_spree', github: 'magiclabs/alchemy_spree', branch: 'master' in your Gemfile and run bundle update alchemy_spree.

    And, regarding to the README you need to add an initializer into your app, if you use spree_auth_devise. Just skipping this step will not work.

    Everything I mentioned above is stated right in the README of the project. Did you follow it?