オブジェクトの作成後に呼び出されるメソッドがあります
after_create :send_welcome_email
これをオブジェクトの属性の値などの条件に制限する方法はありますか
after_create :send_welcome_email unless self.role == "Celebrant"
例えば?
オブジェクトの作成後に呼び出されるメソッドがあります
after_create :send_welcome_email
これをオブジェクトの属性の値などの条件に制限する方法はありますか
after_create :send_welcome_email unless self.role == "Celebrant"
例えば?
これを行うには、Symbol、String、または Proc の 3 つの方法があります。
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