2

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)>'
Carl
  • 1,246
  • 3
  • 21
  • 39
  • hi @uncleasol, could you add to your question also an extract of your `routes.rb`? Did you check if there is anything useful in the issue history of this gem? https://github.com/spree/spree_auth_devise/issues?utf8=%E2%9C%93&q=is%3Aissue%20 – mabe02 Oct 24 '17 at 12:30
  • thanks, @mabe02 - I will post an extract of the routes.rb file this evening, but I did do a search on the issues and don't see anything about removing or uninstalling the gem. – Carl Oct 24 '17 at 14:41
  • @mabe02 - Relevant portions of routes.rb (which is what I think you meant by "an extract") have been included above. Thanks again for the help. – Carl Oct 24 '17 at 20:41
  • Since there was no issue posted at spree_auth_devise about this, I have posted one to see if anyone has anything over there: https://github.com/spree/spree_auth_devise/issues/398 – Carl Oct 26 '17 at 22:27
  • 1
    `git revert` :) – Qwertie Oct 30 '17 at 12:59

1 Answers1

2

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'
dfherr
  • 1,633
  • 11
  • 24
  • I'm trying these things now. I have all of my spree changes in a feature branch, but I'd rather not have to do the install all over again. Mainly because I don't want to have to re-setup my database. – Carl Oct 31 '17 at 22:44
  • I'm trying to rollback the database changes for devise only, but when I try to run rake db:migrate, I'm still getting that same error on AuthenticationHelpers – Carl Oct 31 '17 at 23:07
  • Sorry, I posted that error on GitHub - I will update the post above with the error – Carl Oct 31 '17 at 23:08
  • Update 2 above has the error - hoping that will help – Carl Oct 31 '17 at 23:18
  • i edited my answer. you probably have a reference to `Spree::AuthenticationHelpers` still in your `ApplicationController` – dfherr Nov 02 '17 at 17:22
  • Yes, this was the problem. Though, unfortunately I was unexpectedly away for the past week and the bounty expired. I will see if I can find a way to add it back. – Carl Nov 07 '17 at 16:26
  • @unclesol i automatically got half of it, because of 2 upvotes. I guess not much you can do about it now ;) – dfherr Nov 07 '17 at 16:50