{"id":13400468,"url":"https://github.com/norman/friendly_id","last_synced_at":"2025-05-14T22:05:39.530Z","repository":{"id":393040,"uuid":"10865","full_name":"norman/friendly_id","owner":"norman","description":"FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.","archived":false,"fork":false,"pushed_at":"2024-01-19T01:28:50.000Z","size":3862,"stargazers_count":6191,"open_issues_count":31,"forks_count":592,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-05-14T22:05:04.678Z","etag":null,"topics":["friendly-url","plugin","rails","ruby","slug"],"latest_commit_sha":null,"homepage":"http://norman.github.io/friendly_id/","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/norman.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"parndt"}},"created_at":"2008-04-18T13:16:06.000Z","updated_at":"2025-05-13T04:15:37.000Z","dependencies_parsed_at":"2023-07-05T14:46:35.632Z","dependency_job_id":"4ed633fe-ec85-4c9d-a869-5a06fdb27e10","html_url":"https://github.com/norman/friendly_id","commit_stats":{"total_commits":1426,"total_committers":197,"mean_commits":7.238578680203045,"dds":"0.42356241234221603","last_synced_commit":"a72fac90282ad1e95611eb4bb381dd9d6702209b"},"previous_names":["friendlyid/friendly_id"],"tags_count":96,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norman%2Ffriendly_id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norman%2Ffriendly_id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norman%2Ffriendly_id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norman%2Ffriendly_id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/norman","download_url":"https://codeload.github.com/norman/friendly_id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235687,"owners_count":22036962,"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":["friendly-url","plugin","rails","ruby","slug"],"created_at":"2024-07-30T19:00:52.378Z","updated_at":"2025-05-14T22:05:39.472Z","avatar_url":"https://github.com/norman.png","language":"Ruby","readme":"[![Build Status](https://github.com/norman/friendly_id/workflows/CI/badge.svg)](https://github.com/norman/friendly_id/actions)\n[![Code Climate](https://codeclimate.com/github/norman/friendly_id.svg)](https://codeclimate.com/github/norman/friendly_id)\n[![Inline docs](https://inch-ci.org/github/norman/friendly_id.svg?branch=master)](https://inch-ci.org/github/norman/friendly_id)\n\n# FriendlyId\n\n**For the most complete, user-friendly documentation, see the [FriendlyId Guide](https://norman.github.io/friendly_id/file.Guide.html).**\n\nFriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins for\nActive Record. It lets you create pretty URLs and work with human-friendly\nstrings as if they were numeric ids.\n\nWith FriendlyId, it's easy to make your application use URLs like:\n\n    https://example.com/states/washington\n\ninstead of:\n\n    https://example.com/states/4323454\n\n\n## Getting Help\n\nAsk questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/friendly-id)\nusing the \"friendly-id\" tag, and for bugs have a look at [the bug section](https://github.com/norman/friendly_id#bugs)\n\n## FriendlyId Features\n\nFriendlyId offers many advanced features, including:\n\n * slug history and versioning\n * i18n\n * scoped slugs\n * reserved words\n * custom slug generators\n\n## Usage\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'friendly_id', '~\u003e 5.5.0'\n```\n\nNote: You MUST use 5.0.0 or greater for Rails 4.0+.\n\nAnd then execute:\n\n```shell\nbundle install\n```\n\nAdd a `slug` column to the desired table (e.g. `Users`)\n```shell\nrails g migration AddSlugToUsers slug:uniq\n```\n\nGenerate the friendly configuration file and a new migration\n\n```shell\nrails generate friendly_id\n```\n\nNote: You can delete the `CreateFriendlyIdSlugs` migration if you won't use the slug history feature. ([Read more](https://norman.github.io/friendly_id/FriendlyId/History.html))\n\nRun the migration scripts\n\n```shell\nrails db:migrate\n```\n\nEdit the `app/models/user.rb` file as the following:\n\n```ruby\nclass User \u003c ApplicationRecord\n  extend FriendlyId\n  friendly_id :name, use: :slugged\nend\n```\n\nEdit the `app/controllers/users_controller.rb` file and replace `User.find` by `User.friendly.find`\n\n```ruby\nclass UserController \u003c ApplicationController\n  def show\n    @user = User.friendly.find(params[:id])\n  end\nend\n```\n\nNow when you create a new user like the following:\n\n```ruby\nUser.create! name: \"Joe Schmoe\"\n```\n\nYou can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.\n\n\nIf you're adding FriendlyId to an existing app and need to generate slugs for\nexisting users, do this from the console, runner, or add a Rake task:\n\n```ruby\nUser.find_each(\u0026:save)\n```\n\n## Options\n\n### `:allow_nil`\n\nYou can pass `allow_nil: true` to the `friendly.find()` method if you want to\navoid raising `ActiveRecord::RecordNotFound` and accept `nil`.\n\n#### Example\n\n```ruby\nMyModel.friendly.find(\"bad-slug\") # where bad-slug is not a valid slug\nMyModel.friendly.find(123)        # where 123 is not a valid primary key ID\nMyModel.friendly.find(nil)        # maybe you have a variable/param that's potentially nil\n#=\u003e raise ActiveRecord::RecordNotFound\n\nMyModel.friendly.find(\"bad-slug\", allow_nil: true)\nMyModel.friendly.find(123, allow_nil: true)\nMyModel.friendly.find(nil, allow_nil: true)\n#=\u003e nil\n```\n\n## Bugs\n\nPlease report them on the [Github issue\ntracker](https://github.com/norman/friendly_id/issues) for this project.\n\nIf you have a bug to report, please include the following information:\n\n* **Version information for FriendlyId, Rails and Ruby.**\n* Full stack trace and error message (if you have them).\n* Any snippets of relevant model, view or controller code that shows how you\n  are using FriendlyId.\n\nIf you are able to, it helps even more if you can fork FriendlyId on Github,\nand add a test that reproduces the error you are experiencing.\n\nFor more inspiration on how to report bugs, please see [this\narticle](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).\n\n## Thanks and Credits\n\nFriendlyId was originally created by Norman Clarke and Adrian Mugnolo, with\nsignificant help early in its life by Emilio Tagua. It is now maintained by\nNorman Clarke and Philip Arndt.\n\nWe're deeply grateful for the generous contributions over the years from [many\nvolunteers](https://github.com/norman/friendly_id/contributors).\n\n## License\n\nCopyright (c) 2008-2020 Norman Clarke and contributors, released under the MIT\nlicense.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies 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 THE\nSOFTWARE.\n","funding_links":["https://github.com/sponsors/parndt"],"categories":["SEO","Uncategorized","模型","Ruby","Active Record","WebSocket","Gems"],"sub_categories":["Uncategorized","Omniauth","Articles"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorman%2Ffriendly_id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnorman%2Ffriendly_id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorman%2Ffriendly_id/lists"}