{"id":14955268,"url":"https://github.com/tbhb/sqids-rails","last_synced_at":"2026-02-22T10:41:37.326Z","repository":{"id":246937517,"uuid":"824697312","full_name":"tbhb/sqids-rails","owner":"tbhb","description":"Sqids (formerly Hashids) integration for Ruby on Rails","archived":false,"fork":false,"pushed_at":"2024-12-16T12:19:29.000Z","size":76,"stargazers_count":11,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T08:41:36.451Z","etag":null,"topics":["activerecord","rails","short-id","sqids"],"latest_commit_sha":null,"homepage":"https://github.com/tbhb/sqids-rails","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbhb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-05T18:03:29.000Z","updated_at":"2024-11-05T08:51:24.000Z","dependencies_parsed_at":"2024-09-21T22:41:00.993Z","dependency_job_id":null,"html_url":"https://github.com/tbhb/sqids-rails","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"1e448d5fd20149673faae730562db51258518432"},"previous_names":["tbhb/sqids-rails"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbhb%2Fsqids-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbhb%2Fsqids-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbhb%2Fsqids-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbhb%2Fsqids-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbhb","download_url":"https://codeload.github.com/tbhb/sqids-rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237932070,"owners_count":19389560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","rails","short-id","sqids"],"created_at":"2024-09-24T13:10:47.470Z","updated_at":"2025-10-24T07:31:03.084Z","avatar_url":"https://github.com/tbhb.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# sqids-rails\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/tbhb/sqids-rails/tests.yml)\n![Gem Version](https://img.shields.io/gem/v/sqids-rails)\n\n[Sqids](https://sqids.org) (formerly [Hashids](https://github.com/hashids)) integration for [Ruby on Rails](https://rubyonrails.org).\n\nFrom [sqids-ruby](https://github.com/sqids/sqids-ruby):\n\n\u003e [Sqids](https://sqids.org/ruby) _(pronounced \"squids\")_ is a small library that lets you generate unique IDs from numbers. It's good for link shortening, fast \u0026 URL-safe ID generation and decoding back into numbers for quicker database lookups.\n\u003e\n\u003e Features:\n\u003e\n\u003e - Encode multiple numbers - generate short IDs from one or several non-negative numbers\n\u003e - Quick decoding - easily decode IDs back into numbers\n\u003e - Unique IDs - generate unique IDs by shuffling the alphabet once\n\u003e - ID padding - provide minimum length to make IDs more uniform\n\u003e - URL safe - auto-generated IDs do not contain common profanity\n\u003e - Randomized output - Sequential input provides nonconsecutive IDs\n\u003e - Many implementations - Support for 40+ programming languages\n\n## Getting started\n\nRun `bundle add sqids-rails` or add this line to your application's `Gemfile`:\n\n```ruby\ngem 'sqids-rails'\n```\n\nAnd then execute:\n\n```shell\nbundle\n```\n\n## Usage\n\nAdd auto-generated sqids columns to your ActiveRecord models with `has_sqid`:\n\n```ruby\n# Schema: users(sqid:string, long_sqid:string)\nclass User \u003c ApplicationRecord\n  include Sqids::Rails::Model\n\n  has_sqid\n  has_sqid :long_sqid, min_length: 24\nend\n\nuser = User.new\nuser.save\nuser.sqid # =\u003e \"lzNKgEb6ZuaU\"\nuser.sqid_long # =\u003e \"4y3SVm9M2aV8Olu6p4zZoGij\"\nuser.regenerate_sqid\nuser.regenerate_long_sqid\n```\n\n`has_sqid` follows the same behavior as ActiveRecord's built-in [has_secure_token](https://api.rubyonrails.org/classes/ActiveRecord/SecureToken/ClassMethods.html#method-i-has_secure_token)\n\nUse a custom attribute name (the default is `sqid`):\n\n```ruby\nhas_sqid :uid\n```\n\nEnforce a _minimum length_ for generated IDs:\n\n```ruby\nhas_sqid min_length: 24\n```\n\nProvide a custom alphabet for generated IDs:\n\n```ruby\nhas_sqid alphabet: \"FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE\"\n```\n\nPrevent specific words from appearing anywhere in generated IDs:\n\n```ruby\nhas_sqid blocklist: Set.new(%w[86Rf07])\n```\n\n## Performance considerations\n\n- Consider adding indexes (with uniqueness constraints) when finding records by Sqid.\n- The size of the alphabet can impact performance. A larger alphabet allows for shorter Sqids but slightly increase generation time.\n- The size of the blocklist can impact performance, as each generated ID is checked against the blocklist.\n\n## Roadmap\n\n- [x] `has_sqid` for auto-generating Sqid columns\n- [ ] Extensions to [ActiveRecord::FinderMethods](https://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html) and [ActiveRecord::Associations::CollectionProxy](https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-find) to find records with a Sqid-encoded primary key\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/tbhb/sqids-rails). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tbhb/sqids-rails/blob/main/CODE_OF_CONDUCT.md).\n\n## Acknowledgements\n\nThanks to Ivan Akimov ([@4kimov](https://github.com/4kimov)) for creating and maintaining Sqids and [sqids-ruby](https://github.com/sqids/sqids-ruby), and Roberto Miranda ([@robertomiranda](https://github.com/robertomiranda)) for `has_secure_token`.\n\n## MIT License\n\nCopyright (c) 2024 Anthony Burns\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbhb%2Fsqids-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbhb%2Fsqids-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbhb%2Fsqids-rails/lists"}