Created
April 9, 2009 17:04
-
-
Save jzellman/92598 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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