开发者

How do I trigger an observer when column_name changes?

开发者 https://www.devze.com 2023-03-24 14:31 出处:网络
I want to trigger an email if a new system admin is granted. I have set up开发者_高级运维 a user observer. I want to trigger the email when admin column_name changes to true.

I want to trigger an email if a new system admin is granted. I have set up开发者_高级运维 a user observer. I want to trigger the email when admin column_name changes to true.

More important this change will happen through the console and not through the UI.

Here is what I have:

def after_update(user)
  if user.admin_changed?
    AdminMailer.new_system_administrator(user).deliver
   end
end

finally using dirty? function to trigger the email


Using the is dirty? function on Db column to trigger the email

0

精彩评论

暂无评论...
验证码 换一张
取 消