Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brianpetro/hashids_rails
Use hashids.rb to store ActiveRecord IDs in URL non-obviously.
https://github.com/brianpetro/hashids_rails
Last synced: 1 day ago
JSON representation
Use hashids.rb to store ActiveRecord IDs in URL non-obviously.
- Host: GitHub
- URL: https://github.com/brianpetro/hashids_rails
- Owner: brianpetro
- License: mit
- Created: 2015-04-20T19:16:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T15:12:08.000Z (about 8 years ago)
- Last Synced: 2024-04-26T09:03:16.205Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 29.3 KB
- Stars: 15
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= hashids_rails gem
{}[https://gitter.im/brianpetro/hashids_rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
Uses hashids.rb(https://github.com/peterhellberg/hashids.rb) to store ActiveRecord IDs in URL non-obviously. Heavily based on obfuscate_id(https://github.com/namick/obfuscate_id).
== Installation
Add the gem to your Gemfile.gem 'hashids_rails'
Run bundler.
bundle install
== Usage
In your model, add a single line.class Post < ActiveRecord::Base
hash_id
end== Customization
If you want your hash ids to be different than some other website using the same plugin, you can throw a random string (salt) at hash_id to make it hash out unique ids for your app.class Post < ActiveRecord::Base
hash_id salt: 'bring_your_own_salt'
end== Limitations
* This is not security. hashids_rails was created to lightly mask record id numbers for the casual user. If you need to really secure your database ids (hint, you probably don't), you need to use real encryption like AES.
* To properly generate obfuscated urls(using hash_ids), make sure you trigger the model's to_param method by passing in the whole object rather than just the id; do this: post_path(@post) not this: post_path(@post.id).== Contributing
=== TODO
* write tests