class Model1 < ActiveRecord::Base
include UploadLoginc
before_save do
p "before model"
end
end
module UploadLoginc
extend ActiveSupport::Concern
included do
before_save do
p "before module"
end
end
end
如何在UploadLoginc中将before_save
回调添加到before_save
回调链的末尾?
答案 0 :(得分:0)
我认为你不能,但你可能会对后来的回调有另一个顾虑,并在你的模型回调后包括关注,以便他们以正确的顺序注册。
module UploadLoginc_before
extend ActiveSupport::Concern
included do
before_save :do_something_first
end
end
module UploadLoginc_after
extend ActiveSupport::Concern
included do
before_save :finally_do_this
end
end
class Model1 < ActiveRecord::Base
include UploadLoginc_before
before_save :inbetween_do_this
include UploadLoginc_after
end