Skip to content

Instantly share code, notes, and snippets.

@jzellman
Created April 9, 2009 17:04
Show Gist options
  • Save jzellman/92598 to your computer and use it in GitHub Desktop.
Save jzellman/92598 to your computer and use it in GitHub Desktop.
class Device
validates_uniqueness_of :device_number, :scope => :customer_id
after_create: assign_device_number
def assign_device_number
begin
device_number = self.customer.devices.map(&:device_number).compact.max) || 0 + 1
save!
rescue Whatever gets thrown for validation error
assign_device_number
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment