使用Devise将SpreeCommerce添加到现有应用程序

时间:2014-08-26 02:30:36

标签: ruby-on-rails ruby devise spree

看来我一定是在做错事(我在Spree的初期) 我按照本教程http://guides.spreecommerce.com/developer/authentication.html 我有默认的设计设置,现在正在尝试添加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

这是我在lib / spree

下的authentication_helpers.rb中的代码

我还在spree.rb初始化程序

中添加了以下内容
Spree.user_class = "User"

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

我在" / store"

下安装了狂热引擎

现在。用户表单显然适用于我的应用程序。当我去商店时,我点击了#34; Logout"按预期工作 - 让我从狂欢和我的主应用程序中退出。 Spree中的登录表单给出了以下错误:

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

当我查看会话转储时:

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

用户显然无法在任何地方登录。

注册表单接受输入,在Spree :: User类中保存记录但不允许日志用户以后登录。登录按钮仍然存在,但点击时没有做任何事情。我也没有登录网站的其余部分。

此外,当我尝试打开购物车时(虽然/帐户没有错误):

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

2 个答案:

答案 0 :(得分:1)

右。答案结果非常简单:

而不是向gem文件添加专用的身份验证策略

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

只需使用

gem 'devise'

我同时将它们都包括在内。

答案 1 :(得分:0)

我遇到了你相信的同样问题: Spree :: OrdersController #populate中的ActiveRecord :: AssociationTypeMismatch 狂欢::用户(#70237393066980)预计,有用户(#70237401744200)

和我一样,我将Spree类添加为“User”并使用Devise。

我想问你:

  1. db模式中是否有两个不同的表:users(来自devise)和spree_user?我这样做,我想知道这是不是我的问题。

  2. 我的gemfile没有设计,虽然我使用命令行安装它。但是,我在运行所有狂欢脚本后执行了此操作,因此我的迁移首先在spree中设置所有内容,然后我的设计创建用户迁移。你认为这可能是我的问题吗?