我的Rails 3应用程序有一个控制器,代码如下(粗略简化)示例:
class DogController < ApplicationController
around_filter :notify_owner_of_name_change, only: [update]
around_filter :notify_owner_of_weight_change, only: [update]
...
private
def notify_owner_of_name_change
old_name = @dog.name
yield
new_name = @dog.name
@dog.email_owner("Your dog changed its name from #{old_name} to #{new_name}") if old_name != new_name
end
def notify_owner_of_weight_change
old_weight = @dog.weight
yield
new_weight = @dog.weight
@dog.email_owner("Your dog's weight changed from #{old_weight} to #{new_weight}") if old_weight != new_weight
end
end
当狗的信息更新时,它会命中名称更改过滤器,产生权重更改过滤器,产生更新操作,完成权重更改过滤器,然后完成名称更改过滤器。
此模式是否可能导致数据库级别的死锁?