Conditional Callback in Rails' model?
class LineItem < ActiveRecord::Base
before_create :set_invoice_id, unless: :invoice_id
def set_invoice_id
self.invoice_id = line_item_group.invoice_id
end
end
Yes you can.
class Order < ActiveRecord::Base
before_save :normalize_card_number, :if => :paid_with_card?
end
See http://guides.rubyonrails.org/active_record_callbacks.html#conditional-callbacks for more on this topic.