Hot questions for Using Spree in ruby on rails 5

Top 10 Ruby Open Source / Spree / ruby on rails 5

Question:

I have an existing Rails 5.1 application which already contains a custom user controller.

As I was following the instructions to install Spree, I installed the spree_auth_devise gem and ran the migrations and other install commands as advised on the readme page. As I began working with the gem I found that there was an issue with my User class, and this - of course - was because I had installed the devise gem when I am not using devise.

I have attempted to follow the instructions on how to set up a custom user model when not using devise, but after following these instructions and removing the spree_auth_devise I am unable to launch the site.

When I run the site with the gem installed, my custom routes for "login" etc, do not work. They point to the path where spree is installed and not that defined in my routes.rb.

I'm not sure what to do to remove the gem and get my user model working with spree. Any help is appreciated. I'm not sure what details or code to provide other than this as there are many files affected by this. I will post anything you feel may help.

UPDATE: Per the comment below, here are the spree-relevant portions of my routes.rb. Let me know if you need anything else:

mount Spree::Core::Engine, at: '/store'

get 'login'                                 =>  'sessions#new'
get 'signup'                                =>  'users#new'
delete  'logout'                            =>  'sessions#destroy'
post 'login'                                =>  'sessions#create'

UPDATE 2 I get this error when I try to launch the server or run rake db:migrate...

Exiting
/Users/user/sites/site/app/controllers/application_controller.rb:8:in `<class:ApplicationController>': uninitialized constant Spree::AuthenticationHelpers (NameError)
    from /Users/user/sites/site/app/controllers/application_controller.rb:1:in `<top (required)>'

Answer:

Based on your information, try this:

Remove config/initializers/devise.rb if you haven't done it

remove any devise related code from your routes.rb

Might look similar to this:

devise_for :users, controllers: {
    confirmations: 'users/confirmations',
    passwords: 'users/passwords',
    registrations: 'users/registrations',
    sessions: 'users/sessions',
    unlocks: 'users/unlocks'
}

Check if there are is any code related to devise/spree_auth_devise

Might look like this in your User model:

devise :database_authenticatable, :registerable

Or in your ApplicationController or any other controller (git grep it):

before_action :authenticate_user!

Rollback your database changes (set STEP and RAILS_ENV appropirately):

rake db:rollback STEP=1 RAILS_ENV=development

If nothing helps, try a git revert or git reset

Regarding your error uninitialized constant Spree::AuthenticationHelpers

This module is defined in the spree_auth_gem here and also gets included to your ApplicationController in the engine.

If you did setup spree by this guide remove include Spree::AuthenticationHelpers from your ApplicationController.

Thes includes below might also be unnecessary. I would remove them 1 by 1 and see if your app still works:

include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::Store
helper 'spree/base'

Question:

I have been trying to setup gem spree_static_content with spree 3.X and rails 5 but there are endless errors (migrations not running, gem dependencies) which are coming. Documentation is outdated and no help on any of the gems and spree commerce project. If someone has recently used these projects please share the debugging results.


Answer:

When setting up spree_static_content gem with Rails 5.x and spree 3.x there are various errors you will get when you add only gem spree_static_content to your Gemfile. Install following gems to your Gemfile and you will not get any error and will easily setup cms for static content for your application.

gem 'spree_static_content', github: 'spree-contrib/spree_static_content'

gem 'globalize', git: 'https://github.com/globalize/globalize'
gem 'activemodel-serializers-xml'

gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'

Next, run following commands

bundle install
bundle exec rails g spree_i18n:install
bundle exec rails g spree_globalize:install
bundle exec rails g spree_static_content:install

Now, simply create pages from admin but don't forget to select the store-name checkbox for route to work for spree 3.x.

Question:

I am attempting to precompile my assets after adding the spree gem to my Rails 5 app. It was running fine before I added it, but now I can't get my assets to precompile.

application.scss

@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootsy";
@import "theme";
@import "dropzone";
@import "font-awesome";
@import "spree/frontend/all";
@import "spree/backend/all";
@import "essentials";
@import "custom";

This is what I get with the rake assets:precompile command

rake aborted!
Sass::SyntaxError: Undefined variable: "$navbar-height".
/Users/username/.rvm/gems/ruby-2.4.1/gems/spree_backend-3.3.0/app/assets/stylesheets/spree/backend/components/_sidebar.scss:3

Answer:

The problem was a conflict in the boostrap-sprockets call. Removing that import solved the issue.