Skip to content

Instantly share code, notes, and snippets.

@Killavus
Created May 3, 2016 22:11
Show Gist options
  • Save Killavus/7fa5cdbc645e6829c45410bbc6aa89b1 to your computer and use it in GitHub Desktop.
Save Killavus/7fa5cdbc645e6829c45410bbc6aa89b1 to your computer and use it in GitHub Desktop.
class Customer < ActiveRecord::Base
has_one :auto_created, dependent: :destroy
def self.register(params)
new(params).tap do |customer|
customer.save!
customer.send_welcome_email
end
end
def self.auto_create(params)
new(params).tap do |customer|
customer.save!
end
end
def send_welcome_email
CustomerMailer.welcome_email(self).deliver
end
end
@Bartuz
Copy link

Bartuz commented Jun 17, 2016

I would rename register and auto_create to register! and auto_create! because save! which is called inside may raise an error. What do you think @Killavus ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment