Skip to content

Instantly share code, notes, and snippets.

@kingcu
Created January 12, 2012 19:22
Show Gist options
  • Save kingcu/1602502 to your computer and use it in GitHub Desktop.
Save kingcu/1602502 to your computer and use it in GitHub Desktop.
after_save :save_log_entries
def save_log_entries
return unless @log_entries
@log_entries.each { |e| e.save }
@log_entries = []
end
#in change_subscription method.....
@log_entries ||= []
if new_account_level != self.account_level
@log_entries << SubscriptionLog.new(
subscription_id: self.id,
type_id: Subscription::CHANGE_ACCOUNT_TYPE_CODE,
account_level_before: self.account_level,
account_level_after: new_account_level,
billing_type_before: self.billing_type,
billing_type_after: new_billing_type
)
end
if new_billing_type != self.billing_type
@log_entries << SubscriptionLog.new(
subscription_id: self.id,
type_id: Subscription::CHANGE_BILLING_TYPE_CODE,
account_level_before: self.account_level,
account_level_after: new_account_level,
billing_type_before: self.billing_type,
billing_type_after: new_billing_type
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment