This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Fri Aug 01 16:44:06 -0700 2008 | |
| |
README | Mon Aug 11 07:54:17 -0700 2008 | |
| |
init.rb | Fri Aug 01 16:00:25 -0700 2008 | |
| |
lib/ | Wed May 06 13:36:00 -0700 2009 |
README
acts_as_hashed
==============
Sometimes it's just not OK to expose content from your model into the URL that fetches it. By default, ActiveRecord
uses the model's :id parameter as its param. There are lots of various SEO slug URL plugins, too. This is not one of
them. If you can get away with overriding YourModel#to_param, you should.
acts_as_hashed uses a cryptographic hash function to hash one or more properties of your model, and stores that hash
with the model. You can then look up model instances using that crypto_hash property.
A Sample Use Case: (Scratching my own itch)
I have a Rails application that maintains data that is private to the user that created it. I would also like to give
my users the option of sharing a link to a specific page of their data. Using IDs and slugs are out, but sharing a link
that included an crypto hash, based on one or more properties of that model, would be a nice way to go.
Get it working:
1) install this plugin
2) create a migration that adds a "crypto_hash" text field to each model you'll be hashing
3) rake db:migrate ;)
4) add the acts_as_hashed class method to your model like so:
acts_as_hashed :from => :date
- or -
acts_as_hashed :from => [:id, :date, :heading]
5) save a new model and check out its cryptography hash!
6) ModelName.find_by_crypto_hash("321654987") should do the trick
Notes:
1) each property passed to the :from option must accept a to_s method call
2) I'm currently using crc32 hashing, since they make for nice tidy URL elements, which in turn requires zlib
Copyright (c) 2008 Brian Doll, released under the MIT license







