README.md in permalink-2.1.0 vs README.md in permalink-3.0.0

- old
+ new

@@ -1,38 +1,49 @@ # Permalink -[![Code Climate](https://codeclimate.com/github/fnando/permalink.svg)](https://codeclimate.com/github/fnando/permalink) -[![Build Status](https://travis-ci.org/fnando/permalink.svg)](https://travis-ci.org/fnando/permalink) +[![test](https://github.com/fnando/permalink/actions/workflows/test.yml/badge.svg)](https://github.com/fnando/permalink/actions/workflows/test.yml) [![Gem](https://img.shields.io/gem/v/permalink.svg)](https://rubygems.org/gems/permalink) [![Gem](https://img.shields.io/gem/dt/permalink.svg)](https://rubygems.org/gems/permalink) ## Installation gem install permalink ## Usage +> [!NOTE] +> +> To have the method `permalink` available, you need to inject +> `Permalink.active_record` on each model, or use something like your +> `ApplicationModel`. + +```ruby +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class + include Permalink.active_record +end +``` + Add the method call `permalink` to your model. Your model should have a `permalink` attribute. ```ruby -class Page < ActiveRecord::Base +class Page < ApplicationRecord permalink :title end ``` You can specify the permalink field: ```ruby -class page < ActiveRecord::Base +class Page < ApplicationRecord permalink :title, to: "title_permalink" end ``` -If you don't want to use `permalink`, you can call -`Permalink.generate("some text")` string method and manage the permalink process -by yourself. +If you don't want to use `permalink`, you can call `Permalink.call("some text")` +string method and manage the permalink process by yourself. Permalinks are not unique by default. `permalink` overrides `to_param` as following: ```ruby @@ -42,11 +53,11 @@ ``` You can define the `to_param` format: ```ruby -class Page < ActiveRecord::Base +class Page < ApplicationRecord permalink :title, to_param: %w(id permalink page) end ``` The above settings will generate something link `100-some-title-page`. By @@ -54,20 +65,20 @@ routes. If you want to generate unique permalink, use the `:unique` option: ```ruby -class Page < ActiveRecord::Base +class Page < ApplicationRecord permalink :title, unique: true, to_param: "permalink" end ``` The permalink can be tied to a given scope. Let's say you want to have unique permalinks by user. Just set the `:scope` option. ```ruby -class Page < ActiveRecord::Base +class Page < ApplicationRecord belongs_to :user permalink :title, unique: true, scope: "user_id" end user = User.first @@ -89,17 +100,17 @@ evaluated and the instance has no permalink set. You can force the permalink generation by setting the `:force` option. ```ruby -class Page < ActiveRecord::Base +class Page < ApplicationRecord permalink :title, force: true end ``` ## License -Copyright (c) 2011-2015 Nando Vieira, released under the MIT license +Copyright (c) 2011-2024 Nando Vieira, released under the MIT license Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of