text: Q:
  
  Rails 4 - How to make a callback work only the first time a checkbox is clicked?
  
  How to make a callback work only the first time a checkbox is clicked?
  A "quote" model has a checkbox for approved by client. This initiates a callback that generates an invoice. However each time I check and uncheck the box the callback is initiated each time creating duplicate invoices each time. How can I avoid this?
  code:
  Class Quote<ActiveRecord::Base
  after_save :generate_invoice
  def generate_invoice
    Invoice.create!(date: self.date, quantity: self.quantity, unit_cost: self.unit_cost)
  end
  
  A:
  
  On first callback set invoiced_at, then in all callbacks only invoice if invoiced_at is not present
  def generate_invoice
    if self.invoiced_at.blank?
      Invoice.create!(date: self.date, quantity: self.quantity, unit_cost: self.unit_cost)
      self.invoiced_at = Time.now
      self.save
    end
  end
  
  A:
  
  I know you accepted answer. But don't know why you need this extra column. You can do it without invoiced_at column in two ways.
  
  Check either invoice present for quote or not. You scenario suggest you should have has_one and belongs_to relation present in your quote and invoice model.
  So change your code like this.
  def generate_invoice
    if self.invoice.present?
      Invoice.create!(date: self.date, quantity: self.quantity, unit_cost: self.unit_cost)
    end
  end
  
  Check for created_at and updated_at column in your Quote model. For first time they hold same values. So you can change your code like this also.
  def generate_invoice
    if created_at == updated_at
      Invoice.create!(date: self.date, quantity: self.quantity, unit_cost: self.unit_cost)
    end
  end
  
  