0.01
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0.0
 Project Readme

ActsAsKeyed

![Gitter](https://badges.gitter.im/Join Chat.svg)

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