Coder Social home page Coder Social logo

masterkain / acts-as-keyed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jhubert/acts-as-keyed

1.0 3.0 0.0 81 KB

A simple plugin that automatically generates a key for a model on create.

Home Page: http://www.jeremyhubert.com

License: MIT License

Ruby 100.00%

acts-as-keyed's Introduction

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

acts-as-keyed's People

Contributors

jhubert avatar masterkain avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.