Sha256: c83ce0ebab9ecadc0bf02e5902f1840dbf5e62e18debe69cfb774c55412500c1

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# ActsAsKeyed

A simple plugin that automatically generates a key for a model on create. It takes care of protecting the key, automatically generating it and making sure it is unique.

The key is based on Tantek's NewBase60 schema to make human readable keys, but you can change the chars used by passing in an option to the acts_as_keyed method.

http://tantek.pbworks.com/w/page/19402946/NewBase60

## Options

* **as_params** [*False*] If true, this will be used as the id of the object when creating URLs and you will be able to Object.find(key)
* **size** - [_10_] The number of characters to make the key
* **chars** - [_NewBase60_] An array of Chars to use when generating the key
* **column** - [*key*] The name of the column to store the key. Accepts a symbol or string.

## Example

    create_table "projects" do |t|
      t.string   "key"
    end

    class Project < ActiveRecord::Base
      acts_as_keyed :as_params => true
    end

    Project.create
    Project.first.key 
    => '8xsk38s92p'

    Project.find('8xsk38s92') == Project.find(1)

Copyright (c) 2011 Jeremy Hubert, released under the MIT license

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_keyed-1.0.0 README.md
acts_as_keyed-0.1.3 README.md