Adding SpreeCommerce to an Existing Application with Devise

It seems I must be doing something wrong here (I'm in rudimentary state with Spree) I followed this tutorial http://guides.spreecommerce.com/developer/authentication.html I have a default setting and am now trying to add to it SpreeCommerce.

module Spree
  module AuthenticationHelpers
    def self.included(receiver)
      receiver.send :helper_method, :spree_login_path
      receiver.send :helper_method, :spree_signup_path
      receiver.send :helper_method, :spree_logout_path
      receiver.send :helper_method, :spree_current_user
    end

    def spree_current_user
      current_user
    end

    def spree_login_path
      # main_app.login_path
      main_app.new_user_session_path
    end

    def spree_signup_path
      main_app.new_user_registration_path
    end

    def spree_logout_path
      main_app. destroy_user_session_path
    end
  end
end

Spree::BaseController.send :include, Spree::AuthenticationHelpers
ApplicationController.send :include, Spree::AuthenticationHelpers

      

This is my code in authentication_helpers.rb under lib / spree

I also added the following to my spree.rb initializer

Spree.user_class = "User"

Rails.application.config.to_prepare do
  require_dependency 'spree/authentication_helpers'
end

      

I installed the spree engine under "/ store"

Now. User forms are obviously working in my application. When I go to the store and I hit Logout, which works as expected, it gets me out of the rampage and my main application. The Spree login form gives me the following error:

> RuntimeError in Spree::UserSessionsController#create Could not find a
> valid mapping for nil

      

And when I look at the session dump:

flash: {"discard"=>[], "flashes"=>{"success"=>"Logged in successfully"}}
session_id: "b71cbba980b1375c241d432920865fb6"
warden.user.spree_user.key: [[1], "fL1Ls3yoi8fg7yPFADbx"]

      

The user is clearly not registering anywhere.

The registration form takes input, stores an entry in the Spree :: User class, but does not register a user, and the password is not resolved later. The Login button still exists, but does nothing when clicked. I am also not logged in for the rest of the site.

Also, when I try to open the cart, I get (although / account doesn't give an error):

ActiveRecord::AssociationTypeMismatch in Spree::OrdersController#edit
Spree::User(#70363670728860) expected, got User(#70363741439840) 

      

+3


source to share


2 answers


Right. The answer turns out to be pretty simple:

Instead of adding a dedicated authentication strategy to the gem file

gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-3-stable'

      



Just use

gem 'devise'

      

I turned them both on at the same time.

+1


source


I have the same problem as me. ActiveRecord :: AssociationTypeMismatch in Spree :: OrdersController # populated by Spree :: User (# 70237393066980) expected, received User (# 70237401744200)

Like you, I added the Spree class as "User" and am using Devise.



I would like to ask you:

  • Do you have two different tables in your db schema: users (from development) and spree_user? I do and wonder if this is my problem.

  • My gemfile has no design, although I installed it using the command line. However, I did this after running all the spree scripts, so my migrations first set up everything in order and then my application creates a user migration. Do you think this might be my problem?

0


source







All Articles