No commit activity in last 3 years
No release in over 3 years
This is a gem to generate an unique id in your application world.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

ploymorphic_wuid¶ ↑

Say you want you set an uniq id to an object (whatever it is), and get the object through the id, for example get an object’s versions:

/wuid/:id/versions

return the object through ploymorphic:

obj = Wuid.find(params[:id]).wuidable

Migration¶ ↑

class CreateWuids < ActiveRecord::Migration

def self.up
  create_table :wuids do |t|
    t.integer :wuidable_id
    t.string  :wuidable_type
    t.string  :rand_token
    t.integer :reference_to #optional
    t.timestamps
  end

  add_index :wuids, :rand_token, :unique => true, :name => 'token_index'
end

def self.down
  drop_table :wuids
end

end

Settings¶ ↑

in the environment.rb
  config.gem "ploymorphic_wuid"

in your model

  class Book < ActiveRecord::Base
    acts_as_wuid 
  end

 that's all

Usage¶ ↑

return the object:

  obj = Wuid.find(params[:wuid]).wuidable

now you can both pass in an id or an rand_token to get the corresponding object

get an object's wuid:

  obj.wid

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 tim.teng. See LICENSE for details.