I want to create a unique ID for my user model (called account_id) that is not associated with the primary key. This ID will be provided to the user as another security measure for the user to identify their account.
Here are a few methods in the User model that were helpful in doing this.
Use this with an ActiveRecord callback (after initialize or before create) depending on your need.
possible_id = nil
while possible_id.nil? || User.where(:account_id => possible_id).first
possible_id = generate_id
self.account_id = possible_id
id = ["A"]
id = id.join