Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Using model's sequence next value before inserting for special manipulation.

View client.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# id : serial
# check_digit : integer
 
class Client
 
set_primary_key :id
before_create :define_check_digit
 
private
 
def self.next_id
Integer(connection.select_value "SELECT nextval('#{sequence_name}')")
end
 
def define_check_digit
self.id = self.class.next_id
self.check_digit = Digit.calc id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.