All Projects → dtaniwaki → Acts_as_hashids

dtaniwaki / Acts_as_hashids

Licence: mit
Use Youtube-Like ID in ActiveRecord seamlessly.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Acts as hashids

Activerecordextended
Adds additional postgres functionality to an ActiveRecord / Rails application
Stars: ✭ 830 (+992.11%)
Mutual labels:  activerecord, rails
Activerecord Sqlserver Adapter
SQL Server Adapter For Rails
Stars: ✭ 910 (+1097.37%)
Mutual labels:  activerecord, rails
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+1111.84%)
Mutual labels:  activerecord, rails
Rein
Database constraints made easy for ActiveRecord.
Stars: ✭ 657 (+764.47%)
Mutual labels:  activerecord, rails
Ar Uuid
Override migration methods to support UUID columns without having to be explicit about it.
Stars: ✭ 41 (-46.05%)
Mutual labels:  activerecord, rails
Paper trail
Track changes to your rails models
Stars: ✭ 6,185 (+8038.16%)
Mutual labels:  activerecord, rails
Hold please
📞 Disable ActiveRecord callbacks in Rails for great justice!
Stars: ✭ 20 (-73.68%)
Mutual labels:  activerecord, rails
Stateful enum
A very simple state machine plugin built on top of ActiveRecord::Enum
Stars: ✭ 546 (+618.42%)
Mutual labels:  activerecord, rails
Spreadsheet architect
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets super easily from ActiveRecord relations, plain Ruby objects, or tabular data.
Stars: ✭ 1,160 (+1426.32%)
Mutual labels:  activerecord, rails
Drafting
Ruby gem for saving drafts of ActiveRecord models
Stars: ✭ 41 (-46.05%)
Mutual labels:  activerecord, rails
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+747.37%)
Mutual labels:  activerecord, rails
Fresh connection
FreshConnection provides access to one or more configured database replicas.
Stars: ✭ 56 (-26.32%)
Mutual labels:  activerecord, rails
Unread
Handle unread records and mark them as read with Ruby on Rails
Stars: ✭ 638 (+739.47%)
Mutual labels:  activerecord, rails
Activerecord Postgis Adapter
ActiveRecord connection adapter for PostGIS, based on postgresql and rgeo
Stars: ✭ 746 (+881.58%)
Mutual labels:  activerecord, rails
Github Ds
A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection
Stars: ✭ 597 (+685.53%)
Mutual labels:  activerecord, rails
Active record doctor
Identify database issues before they hit production.
Stars: ✭ 865 (+1038.16%)
Mutual labels:  activerecord, rails
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (+575%)
Mutual labels:  activerecord, rails
Activerecord Multi Tenant
Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
Stars: ✭ 526 (+592.11%)
Mutual labels:  activerecord, rails
Chinese regions rails
中国省市区县数据库,包含行政编码,邮政编码,地区拼音和简拼
Stars: ✭ 38 (-50%)
Mutual labels:  activerecord, rails
Logidze
Database changes log for Rails
Stars: ✭ 1,060 (+1294.74%)
Mutual labels:  activerecord, rails

acts_as_hashids

Gem Version Download Build Status Coverage Status Code Climate

Use Hashids (a.k.a. Youtube-Like ID) in ActiveRecord seamlessly.

Installation

Add the acts_as_hashids gem to your Gemfile.

gem "acts_as_hashids"

And run bundle install.

Usage

Activate the function in any model of ActiveRecord::Base.

class Foo < ActiveRecord::Base
  acts_as_hashids
end

foo = Foo.create
# => #<Foo:0x007feb5978a7c0 id: 3>

foo.to_param
# => "ePQgabdg"

Foo.find(3)
# => #<Foo:0x007feb5978a7c0 id: 3>

Foo.find("ePQgabdg")
# => #<Foo:0x007feb5978a7c0 id: 3>

Foo.with_hashids("ePQgabdg").first
# => #<Foo:0x007feb5978a7c0 id: 3>

Use in Rails

Only one thing you need to hash ids is put acts_as_hashids in ApplicationRecord, then you will see hash ids in routes URL and they are handled correctly as long as you use find to find records.

Options

length

You can customize the length of hash ids per model. The default length is 8.

class Foo < ActiveRecord::Base
  acts_as_hashids length: 2
end

Foo.create.to_param
# => "Rx"

secret

You can customize the secret of hash ids per model. The default secret is the class name. The name of base class is used for STI.

class Foo1 < ActiveRecord::Base
  acts_as_hashids secret: 'my secret'
end

class Foo2 < ActiveRecord::Base
  acts_as_hashids secret: 'my secret'
end

Foo1.create.to_param
# => "RxQce3a2"

Foo2.create.to_param
# => "RxQce3a2"

alphabet

Specify which characters you use to generate hashids.

class Foo < ActiveRecord::Base
  acts_as_hashids alphabet: '0123456789uvwxyz'
end

Foo.create(id: 1).to_param
# => "4xw8zwyv"

Test

Execute the command below to run rspec and rubocop.

bundle exec rake

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2014 Daisuke Taniwaki. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].