Sha256: 154ddff2696eb4ab1b5b2317b9386f7e9a78f548161bde3209cdb3d242d3782d

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

= 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

  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

Copyright (c) 2010 tim.teng. See LICENSE for details.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ploymorphic_wuid-0.5.0 README.rdoc