2011-09-06 5 views

Trả lời

33

Có ba cách để thực hiện việc này: Biểu tượng, Chuỗi hoặc 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 

Documentation

+2

các chi tiết tài liệu đã được chuyển tới [ở đây] (http://guides.rubyonrails.org/active_record_callbacks.html#using-if-and-unless-with-a-symbol) – gotva