{"id":15502900,"url":"https://github.com/johno/urls_for_humans","last_synced_at":"2025-10-12T16:06:23.045Z","repository":{"id":16035781,"uuid":"18779600","full_name":"johno/urls_for_humans","owner":"johno","description":"Apply persistent, meaningful urls to your Rails app.","archived":false,"fork":false,"pushed_at":"2015-01-27T07:15:16.000Z","size":228,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T16:04:32.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://johnotander.com/rails/2014/04/24/urls-for-humans/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"RocketMap/RocketMap","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-14T22:50:48.000Z","updated_at":"2017-08-22T20:27:11.000Z","dependencies_parsed_at":"2022-09-13T20:10:28.480Z","dependency_job_id":null,"html_url":"https://github.com/johno/urls_for_humans","commit_stats":null,"previous_names":["johnotander/urls_for_humans"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/johno/urls_for_humans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Furls_for_humans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Furls_for_humans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Furls_for_humans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Furls_for_humans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johno","download_url":"https://codeload.github.com/johno/urls_for_humans/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Furls_for_humans/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011983,"owners_count":26085039,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-02T09:11:31.545Z","updated_at":"2025-10-12T16:06:23.029Z","avatar_url":"https://github.com/johno.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Urls for Humans\n\n[![Build Status](https://travis-ci.org/johnotander/urls_for_humans.svg?branch=master)](https://travis-ci.org/johnotander/urls_for_humans)\n\nUrls for Humans is a gem that allows you to apply meaningful names to your Rails Application's urls\nby leveraging what happens under the covers with `Model.find(params[:id])`, `to_i`, and `to_param`.\nThis makes it easy to turn `users/1` to `users/1-john-otander`. So long as the url is prefixed with\nthe model's `id` (which Urls for Humans ensures), the lookup will happen exactly how we intend it\nto with a few key benefits:\n\n  * Simple thanks to ActiveSupport.\n  * Lightweight, weighing in at roughly 20 something lines of added gem code to your Rails app (since\n  ActiveSupport is already a dependency).\n  * Persistent urls because changes in the latter portions of a param won't affect it's lookup.\n  * There are no slugs required.\n\n### Why use Urls for Humans in place of Friendly ID?\n\nThis is a different approach to friendly URLs than the `friendly_id` gem because it doesn't modify\nthe db queries themselves. The `urls_for_humans` approach essentially allows all urls fitting the\nform `resource/\u003cid\u003e-\u003canything else\u003e` to route to `resource/:id` because `to_i` is called on the\n`id` parameter.\n\nPersonally, I prefer this approach because a link out there in the wild to a user's profile\n`users/previous_username` isn't broken (404'd) when they change their username to `users/new_username`\nbecause the slug has been changed.\n\nAlso, I'm biased.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'urls_for_humans'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install urls_for_humans\n```\n\n## Usage\n\n\nTo use Urls For Humans you need to extend the `UrlsForHumans` module, and call the class method\n`urls_for_humans`:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include UrlsForHumans\n\n  # ...\n\n  urls_for_humans :first_name, :last_name\n\n  # ...\nend\n```\n\nThe `urls_for_humans` method can be a collection of any information that you'd like to include in\nthe url. For example, with the above class we'd result in:\n\n```ruby\nu = User.create(first_name: 'John', last_name: 'Otander')\n\nu.to_param\n# =\u003e '1-john-otander'\n\nu.first_name = nil\nu.to_param\n# =\u003e '1-otander'\n```\n\nWith this solution, an ActiveRecord object will always produce the correct url throughout the\napplication:\n\n```ruby\nlink_to user.first_name, user\n# =\u003e \u003ca href=\"http://localhost:3000/users/1-john-otander\"\n```\n\nAdditionally, any link that hits the internet will persist because `1-random-content`, `1-other-random-content`,\nand `1-john-doe` will all route to the same resource.\n\n### I don't like it when you leverage executable class bodies\n\nThat's fine. You can add a method to your model, instead.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include UrlsForHumans\n\n  # ...\n\n  def humanly_attrs\n    [:first_name, :last_name, :favorite_food]\n  end\n\n  # ...\nend\n```\n\nThis will result in `\"#{ id }-#{ first_name }-#{ last_name }-#{ favorite_food }\"`. Yay.\n\n## Resources\n\n  * \u003chttps://github.com/norman/friendly_id\u003e\n  * \u003chttps://gist.github.com/cdmwebs/1209732\u003e\n\n## Contributing\n\n1. Fork it ( http://github.com/johnotander/urls_for_humans/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\nCrafted with \u003c3 by [John Otander](http://johnotander.com) ([@4lpine](https://twitter.com/4lpine)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohno%2Furls_for_humans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohno%2Furls_for_humans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohno%2Furls_for_humans/lists"}