Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rails plugin for generating random id
Ruby
branch: master

This branch is 12 commits ahead of hashtrain:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE
README.rdoc
Rakefile
acts_as_random_id.gemspec

README.rdoc

ActsAsRandomId

Generating unique random id for ActiveRecord models

Example

class Comment < ActiveRecord::Base
  acts_as_random_id
end

class Group < ActiveRecord::Base
  acts_as_random_id do
    rand(3_14159265) + 1
  end
end

class Article < ActiveRecord::Base
  acts_as_random_id :field => :secure_identifier do
    Time.now.to_i
  end
end

Install

gem install hashtrain-acts_as_random_id --source http://gems.github.com

Usage

As you know rails generates field ID easy auto_incriment. Thus, there is an opportunity to check how many objects in the DB. Sometimes it's secret information.

Using the plugin “acts_as_random_id” could generate a unique value ID. Generation of ID will be until you will find a unique value ID. Of course you go to the full responsibility for the range. By default, the plugin “acts_as_random_id” generates a unique ID in the range of 1 to 2_147_483_647 (mysql and SQLite type integer)

class Comment < ActiveRecord::Base
  acts_as_random_id
end

You can specify a range of transfer method “acts_as_random_id” block where the generator is implemented

class Group < ActiveRecord::Base
  acts_as_random_id do
    rand(3_14159265) + 1
  end
end

License

Copyright © 2009-2011 Shalva Usubov and author idea Stanislav Pogrebnyak (stanislav.pogrebnyak@gmail.com), released under the MIT license.

Something went wrong with that request. Please try again.