README.md in has_public_id-1.1.0 vs README.md in has_public_id-1.1.5
- old
+ new
@@ -1,24 +1,21 @@
# Public Id
## Description
-Simplifies the generation and use of random, secure ID's in your activerecord models.
+Simplifies the generation and use of unique, random identifiers for ActiveRecord models.
-Uses SecureRandom.urlsafe_base64(10) by default, which generates a 14 character
-base 64 encoded string with the following characters: a-z, A-Z, 0-10, "-" and "_".
+We generate a string of random (using SecureRandom) alphanumeric characters (a-z, A-Z, 0-9) along with an optional prefix that defaults to the first 3 characters of the model name. The random string has a default length of 12, providing 62 ^ 12 possible strings.
-Assuming an even distribution, this allows for 64 ^ 14 different possible encodings
-with the default settings.
+On assignment to the model, if duplicate ID is detected in
+the database, a new random identifier is generated.
-Even so, the plugin is smart enough to discard ID's that are already in use for
-a given model and try again.
-
## Installation
Add to Gemfile / etc
- gem 'public_id'
+ gem 'public_id'
+
## Usage
Add an additional identifier column. I called it "ident", but call it whatever you want.
```sh
# Identifier column MUST be a string
@@ -26,14 +23,14 @@
```
Tell your activerecord object that ident is your new public identifier.
```ruby
class User < ActiveRecord::Base
- has_public_id :ident
+ has_public_id :ident, prefix: 'user'
# Automatically defines to_param as :ident
end
User.new.ident
-# => "use-ECNrdIzvCBh8jg"
+# => "user-ECNrdIzvCBh8"
```
Now change your controllers to lookup the public ID instead of your database ID
```ruby