{"id":19711710,"url":"https://github.com/brightcommerce/attr_slug","last_synced_at":"2025-04-29T18:30:46.377Z","repository":{"id":59150823,"uuid":"162946148","full_name":"brightcommerce/attr_slug","owner":"brightcommerce","description":"AttrSlug is an ActiveRecord concern that automatically generates slug fields using array of attributes.s","archived":false,"fork":false,"pushed_at":"2018-12-24T03:45:46.000Z","size":4,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T01:50:21.609Z","etag":null,"topics":["activerecord","attributes","concerns","ruby-on-rails","slug"],"latest_commit_sha":null,"homepage":null,"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/brightcommerce.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-24T03:31:34.000Z","updated_at":"2019-01-07T01:20:31.000Z","dependencies_parsed_at":"2022-09-13T10:50:17.808Z","dependency_job_id":null,"html_url":"https://github.com/brightcommerce/attr_slug","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightcommerce%2Fattr_slug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightcommerce%2Fattr_slug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightcommerce%2Fattr_slug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightcommerce%2Fattr_slug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brightcommerce","download_url":"https://codeload.github.com/brightcommerce/attr_slug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251559730,"owners_count":21609063,"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","attributes","concerns","ruby-on-rails","slug"],"created_at":"2024-11-11T22:13:29.697Z","updated_at":"2025-04-29T18:30:46.032Z","avatar_url":"https://github.com/brightcommerce.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AttrSlug\n\nAttrSlug is an ActiveRecord concern that automatically generates slug fields using array of attributes.\n\n## Installation\n\nTo install add the line to your `Gemfile`:\n\n``` ruby\ngem 'attr_slug'\n```\n\nAnd run `bundle install`.\n\n## Usage\n\nAttrSlug expects a `slug` column to exist on the model. It is good practice to add an unique index on the column.\n\n``` ruby\n# db/migrations/20180101000000_create_posts.rb\nclass CreatePosts \u003c ActiveRecord::Migration[5.2]\n  def change\n    create_table :posts do |table|\n      table.column :content, :text\n      table.column :slug, :string, null: false, index: {unique: true)\n      table.column :title, :string, null: false\n    end\n  end\nend\n```\n\nYou then include the AttrSlug module in your model class and use the `attr_slug` macro to set your fields you wish to use to derive it's slug.\n\n``` ruby\n# app/models/post.rb\nclass Post \u003c ActiveRecord::Base\n  include AttrSlug\n\n  attr_slug :title, :id\n\n  validates :slug, presence: true, uniqueness: true\n  validates :title, presence: true\nend\n```\n\nUsing the examples above, creating a Post instance will automatically generate the slug field:\n\n``` ruby\npost = Post.create title: \"Test Post\"\npost.slug # \"test-post-1234\"\n```\n\nAttrSlug doesn't modify any ActiveRecord finders. To automatically use the slug in URLs override the model's `to_param` method:\n\n``` ruby\n# app/models/post.rb\nclass Post \u003c ActiveRecord::Base\n  ...\n\n  def to_param # overridden\n    slug\n  end\nend\n```\n\nYou should then use the following to retrieve your models in the controller:\n\n```ruby\ndef show\n  @post = Post.find_by(slug: params[:id])\nend\n```\n\nTo autoload AttrSlug for all models, add the following to an initializer:\n\n``` ruby\nrequire 'attr_slug/active_record'\n```\n\nYou then don't need to `include AttrSlug` in any model.\n\n## Dependencies\n\nAttrSlug gem has the following runtime dependencies:\n- activerecord \u003e= 5.1.4\n- activesupport \u003e= 5.1.4\n\n## Compatibility\n\nTested with MRI 2.4.2 against Rails 5.2.2.\n\n## Contributing\n\n1. Fork it\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\n## Credit\n\nThis gem was written and is maintained by [Jurgen Jocubeit](https://github.com/JurgenJocubeit), CEO and President Brightcommerce, Inc.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## Copyright\n\nCopyright 2018 Brightcommerce, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightcommerce%2Fattr_slug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrightcommerce%2Fattr_slug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightcommerce%2Fattr_slug/lists"}