README.md in prefixed_ids-1.2.2 vs README.md in prefixed_ids-1.3.0
- old
+ new
@@ -32,13 +32,29 @@
end
```
This will generate a value like `user_1234abcd`.
-To query using the prefixed ID, simply you can use either `find` or `find_by_prefixed_id`:
+##### Prefix ID Param
+To retrieve the prefix ID, simply call:
+
```ruby
+User.to_param
+```
+
+If `to_param` override is disabled:
+
+```ruby
+User.prefix_id
+```
+
+##### Query by Prefixed ID
+
+To query using the prefixed ID, you can use either `find` or `find_by_prefix_id`:
+
+```ruby
User.find("user_5vJjbzXq9KrLEMm32iAnOP0xGDYk6dpe")
User.find_by_prefix_id("user_5vJjbzXq9KrLEMm32iAnOP0xGDYk6dpe")
```
We also override `to_param` by default so it'll be used in URLs automatically.
@@ -49,27 +65,46 @@
class User < ApplicationRecord
has_prefix_id :user, override_find: false, override_param: false
end
```
-### Generic lookup
+##### Salt
+A salt is a secret value that makes it impossible to reverse engineer IDs. We recommend adding a salt to make your Prefix IDs unguessable.
+
+###### Global Salt
+
+```ruby
+# config/initializers/prefixed_ids.rb
+PrefixID.salt = "salt"
+```
+
+###### Per Model Salt
+
+```ruby
+class User
+ has_prefix_id :user, salt: "usersalt"
+end
+```
+
+### Generic Lookup By Prefix ID
+
Imagine you have a prefixed ID but you don't know which model it belongs to.
```ruby
PrefixedIds.find("user_5vJjbzXq9KrLEMm3")
#=> #<User>
PrefixedIds.find("acct_2iAnOP0xGDYk6dpe")
#=> #<Account>
```
-### Customizing
+### Customizing Prefix IDs
You can customize the prefix, length, and attribute name for PrefixedIds.
```ruby
class Account < ApplicationRecord
- has_prefix_id :acct, minimum_length: 32, override_find: false, to_param: false
+ has_prefix_id :acct, minimum_length: 32, override_find: false, to_param: false, salt: ""
end
```
## Development