0

我正在尝试在 Solidus 框架之上构建一个朋友功能,但在与 Spree::Users 建立多对多关系时遇到了麻烦。我尝试制作一个 user_decorator.rb 文件(在模型/狂欢中),但一直遇到错误:“预期 user_decorator.rb 来定义 Spree::UserDecorator,但没有”。

用户装饰器:

 Spree::User.class_eval do
   has_many :friendships
   has_many :friends, through: :friendships
 end

友谊模型:

 class Friendship < ActiveRecord::Base
   belongs_to :spree_user, :class_name => 'Spree::User'
   belongs_to :friend, :class_name => 'Spree::User'
 end

错误:

https://i.stack.imgur.com/QOpEU.png

4

1 回答 1

1

将内容替换app/models/spree/user_decorator为:

module Spree
  module UserDecorator
    def self.prepended(base)
      base.has_many :friendships
      base.has_many :friends, through: :friendships
    end

    Spree::User.prepend self
  end
end
于 2020-02-27T09:32:15.673 回答