0

是否可以在关注点中使用 Amoeba 宝石?目前,当我尝试在关注中运行它时出现此错误:

undefined method `amoeba' for Amoeba:Module

相同的代码在实际模型中运行良好,但我想干掉它,因为它在我的两个模型之间非常相似......这是关注点的样子:

module Amoeba
  extend ActiveSupport::Concern

  amoeba do
    enable
    customize(lambda { |original, clone|
      clone.uid        = SecureRandom.hex(2)
      clone.activities = []

    if original.class.name == "Widget"
      clone.bookings   = []
    end

    if orignal.class.name == "Flotsam"
      clone.remaining  = 100
      if original.expiration.past?
        clone.expiration = Date.today + 5.years
      end
    end

    if original.icon.present?
      clone.icon = original.icon
    end
    if original.pdf.present?
      clone.pdf = original.pdf
    end
  })
end
4

1 回答 1

1

amoeba 是一个类方法。使用 ActiveSupport::Concern 它应该在包含的块中调用

module Amoeba
  extend ActiveSupport::Concern
  included do
    amoeba do 
    ....
    end
  end

ActiveSupport::关注

于 2014-07-14T08:31:43.407 回答