Ruby on rails 克隆时跳过阿米巴gem中的回调
考虑一个基本结构,a类有许多B类。 现在,在克隆对象时,我想跳过对象B的回调。如何做到这一点? 我们通常使用attr_访问器来实现这一点,但我也无法做到这一点 这个问题是从很久以前开始的Ruby on rails 克隆时跳过阿米巴gem中的回调,ruby-on-rails,ruby,ruby-on-rails-4,ruby-on-rails-5,amoeba-gem,Ruby On Rails,Ruby,Ruby On Rails 4,Ruby On Rails 5,Amoeba Gem,考虑一个基本结构,a类有许多B类。 现在,在克隆对象时,我想跳过对象B的回调。如何做到这一点? 我们通常使用attr_访问器来实现这一点,但我也无法做到这一点 这个问题是从很久以前开始的 class File < ApplicationRecord amoeba do enable include_association :attachments end has_many :attachments end class Attachment &
class File < ApplicationRecord
amoeba do
enable
include_association :attachments
end
has_many :attachments
end
class Attachment < ApplicationRecord
attr_accessor :skip_processing
amoeba do
enable
# This is wrong
set :skip_processing => true
end
belongs_to :file
after_commit :process_attachment, on: :create, unless: :skip_processing
end
类文件true
结束
属于:文件
提交后:处理附件,在::创建,除非::跳过处理
结束
在阿米巴块中使用attr_访问器时出现了一些错误,我认为我们只能使用DB值。
有什么解决方案吗?阿米巴宝石提供了不同的预处理器,其中一个就是我在这里使用的定制。 可以传递lambda函数或lambda函数数组,在其中可以调用方法或设置克隆对象的属性。我使用它来设置attr_访问器,如下所示-
class Attachment < ApplicationRecord
attr_accessor :skip_processing
amoeba do
enable
customize (lambda { |original, cloned|
# Set attr_accessor here
cloned.skip_processing = true
})
end
belongs_to :file
after_commit :process_attachment, on: :create, unless: :skip_processing
end
类附件