我有一个在创建对象后调用的方法
after_create :send_welcome_email
有没有办法将此限制为条件,例如对象属性的值
after_create :send_welcome_email unless self.role == "Celebrant"
例如?
答案 0 :(得分:37)
有三种方法可以执行此操作:Symbol,String或Proc。
class User < ActiveRecord::Base
after_create :send_welcome_email, unless: :is_celebrant?
after_create :send_welcome_email, unless: "is_celebrant?"
after_create :send_welcome_email, unless: Proc.new { self.role == "Celebrant" }
end