2014-04-17 43 views
1
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回调链结束了吗?轨道4,如何添加模型回调从关注

回答

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