friendly_id 5.2.3 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/stale.yml +17 -0
- data/.github/workflows/test.yml +60 -0
- data/Changelog.md +43 -1
- data/Gemfile +3 -0
- data/README.md +61 -168
- data/Rakefile +2 -2
- data/UPGRADING.md +115 -0
- data/certs/parndt.pem +25 -0
- data/friendly_id.gemspec +7 -3
- data/gemfiles/{Gemfile.rails-4.2.rb → Gemfile.rails-5.2.rb} +4 -5
- data/gemfiles/{Gemfile.rails-4.1.rb → Gemfile.rails-6.0.rb} +5 -7
- data/lib/friendly_id/base.rb +4 -8
- data/lib/friendly_id/candidates.rb +0 -2
- data/lib/friendly_id/configuration.rb +3 -2
- data/lib/friendly_id/finder_methods.rb +18 -7
- data/lib/friendly_id/finders.rb +1 -1
- data/lib/friendly_id/history.rb +21 -12
- data/lib/friendly_id/initializer.rb +11 -0
- data/lib/friendly_id/migration.rb +9 -3
- data/lib/friendly_id/object_utils.rb +9 -2
- data/lib/friendly_id/scoped.rb +8 -1
- data/lib/friendly_id/sequentially_slugged.rb +12 -2
- data/lib/friendly_id/slug.rb +4 -0
- data/lib/friendly_id/slugged.rb +2 -2
- data/lib/friendly_id/version.rb +1 -1
- data/test/databases.yml +6 -4
- data/test/finders_test.rb +24 -0
- data/test/helper.rb +13 -3
- data/test/history_test.rb +86 -7
- data/test/numeric_slug_test.rb +31 -0
- data/test/object_utils_test.rb +2 -0
- data/test/schema.rb +19 -2
- data/test/scoped_test.rb +13 -0
- data/test/sequentially_slugged_test.rb +59 -0
- data/test/shared.rb +2 -2
- data/test/simple_i18n_test.rb +2 -2
- data/test/slugged_test.rb +168 -4
- metadata +44 -16
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -40
- data/gemfiles/Gemfile.rails-4.0.rb +0 -30
- data/gemfiles/Gemfile.rails-5.0.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ba26f9f615f068d0094f6646a6c6a5aceef44b59bde321aa168542b62420402f
|
|
4
|
+
data.tar.gz: 155666a337c2162adc31c2b3337867a7086b63cba390d6d9c6ca8486b7d663d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc67ddc3c8940a7b0bcf0c918c0f5f398e1f484d72fde5fa7f1136035d34ac77a25b0db3ac4070fc0abd21abe926e2d15bc9f536e4f57ddb0dcd84c4f787b1b0
|
|
7
|
+
data.tar.gz: 1e590565fff83c890ee04dede81e518c98912214dc3122690763ee1731559fd337421bd05c4d201224cddd67891416054a81e7d8b0bbc24acfc2e6661e5ebe03
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data.tar.gz.sig
ADDED
|
Binary file
|
data/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
github: parndt
|
data/.github/stale.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
|
2
|
+
daysUntilStale: 84
|
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
|
4
|
+
daysUntilClose: 7
|
|
5
|
+
# Issues with these labels will never be considered stale
|
|
6
|
+
exemptLabels:
|
|
7
|
+
- pinned
|
|
8
|
+
- security
|
|
9
|
+
# Label to use when marking an issue as stale
|
|
10
|
+
staleLabel: stale
|
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
+
markComment: >
|
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
|
15
|
+
for your contributions.
|
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
+
closeComment: false
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- 'master'
|
|
7
|
+
pull_request:
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
architecture: [ x64 ]
|
|
13
|
+
database: [ mysql, postgresql ]
|
|
14
|
+
gemfile: [ '6.0', '5.2' ]
|
|
15
|
+
ruby: [ '2.7.x', '2.6.x', '2.5.x' ]
|
|
16
|
+
fail-fast: false
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
name: ${{ matrix.ruby }} ${{ matrix.database }} rails-${{ matrix.gemfile }}
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/setup-ruby@v1.0.0
|
|
21
|
+
with:
|
|
22
|
+
architecture: ${{ matrix.architecture }}
|
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
|
24
|
+
version: ${{ matrix.ruby }}
|
|
25
|
+
- uses: actions/checkout@v2
|
|
26
|
+
- run: sudo apt-get update && sudo apt-get install libpq-dev postgresql-client libmysqlclient-dev mysql-client libsqlite3-dev -y
|
|
27
|
+
- id: cache-bundler
|
|
28
|
+
uses: actions/cache@v2
|
|
29
|
+
with:
|
|
30
|
+
path: vendor/bundle
|
|
31
|
+
key: ${{ matrix.ruby }}-gem-${{ hashFiles(format('gemfiles/Gemfile.rails-{0}.rb', matrix.gemfile)) }}
|
|
32
|
+
- run: gem install bundler
|
|
33
|
+
- run: bundle install --path vendor/bundle
|
|
34
|
+
- run: bundle exec rake db:create db:up
|
|
35
|
+
- run: bundle exec rake test
|
|
36
|
+
|
|
37
|
+
env:
|
|
38
|
+
BUNDLE_JOBS: 4
|
|
39
|
+
BUNDLE_GEMFILE: gemfiles/Gemfile.rails-${{ matrix.gemfile }}.rb
|
|
40
|
+
BUNDLE_PATH: vendor/bundle
|
|
41
|
+
CI: true
|
|
42
|
+
COVERALLS: true
|
|
43
|
+
DB: ${{ matrix.database }}
|
|
44
|
+
MYSQL_PASSWORD: root
|
|
45
|
+
PGHOST: localhost
|
|
46
|
+
PGPORT: 5432
|
|
47
|
+
PGUSER: postgres
|
|
48
|
+
RAILS_ENV: test
|
|
49
|
+
|
|
50
|
+
services:
|
|
51
|
+
postgres:
|
|
52
|
+
image: postgres:11.5
|
|
53
|
+
ports: ["5432:5432"]
|
|
54
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
55
|
+
mysql:
|
|
56
|
+
image: mysql:5.7
|
|
57
|
+
ports: ["3306:3306"]
|
|
58
|
+
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
|
|
59
|
+
env:
|
|
60
|
+
MYSQL_ROOT_PASSWORD: root
|
data/Changelog.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
3
3
|
We would like to think our many [contributors](https://github.com/norman/friendly_id/graphs/contributors) for
|
|
4
4
|
suggestions, ideas and improvements to FriendlyId.
|
|
5
5
|
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## 5.4.1 (2020-11-06)
|
|
9
|
+
|
|
10
|
+
* Fix unexpected `:slug` error on valid, unpersisted model ([#952](https://github.com/norman/friendly_id/pull/952))
|
|
11
|
+
|
|
12
|
+
## 5.4.0 (2020-08-14)
|
|
13
|
+
|
|
14
|
+
* Fix Ruby 2.7 keyword params deprecation warning ([#939](https://github.com/norman/friendly_id/pull/939))
|
|
15
|
+
* Fix Slug Validation in `unset_slug_if_invalid` ([#938](https://github.com/norman/friendly_id/pull/938))
|
|
16
|
+
* Make `first_by_friendly_id` case insensitive using `downcase` ([#787](https://github.com/norman/friendly_id/pull/787))
|
|
17
|
+
* Use `destroy_all` rather than `delete_all` when creating historical slugs ([#924](https://github.com/norman/friendly_id/pull/924))
|
|
18
|
+
* Set required ruby version to `>= 2.1.0` ([#923](https://github.com/norman/friendly_id/pull/923))
|
|
19
|
+
* Avoid using deprecated `update_attributes` ([#922](https://github.com/norman/friendly_id/pull/922))
|
|
20
|
+
|
|
21
|
+
## 5.3.0 (2019-09-25)
|
|
22
|
+
|
|
23
|
+
* Record history when scope changes but slug does not ([#916](https://github.com/norman/friendly_id/pull/916))
|
|
24
|
+
* Add support for Rails 6 ([#897](https://github.com/norman/friendly_id/pull/897))
|
|
25
|
+
|
|
26
|
+
## 5.2.5 (2018-12-30)
|
|
27
|
+
|
|
28
|
+
* Pass all possible parameters to ActiveRecord::RecordNotFound.new when raising the exception ([#890](https://github.com/norman/friendly_id/pull/890))
|
|
29
|
+
* Use composite index for queries by sluggable ([#882](https://github.com/norman/friendly_id/pull/882))
|
|
30
|
+
* Scoped: generate new slug if scope changed ([#878](https://github.com/norman/friendly_id/pull/878))
|
|
31
|
+
* Fix History + SequentiallySlugged issues ([#877](https://github.com/norman/friendly_id/pull/877))
|
|
32
|
+
* Support scoped with STI ([#745](https://github.com/norman/friendly_id/pull/745))
|
|
33
|
+
* Fix exists? to behave the same as find for numeric slugs ([#875](https://github.com/norman/friendly_id/pull/875))
|
|
34
|
+
* Remove dirty tracking code from to_param ([#867](https://github.com/norman/friendly_id/pull/867))
|
|
35
|
+
|
|
36
|
+
## 5.2.4 (2018-04-24)
|
|
37
|
+
|
|
38
|
+
* Fix compatibility with Rails versions 4.0 -> 5.2. ([#863](https://github.com/norman/friendly_id/pull/863)).
|
|
39
|
+
* Refactor `History::FinderMethods` to use base implementation. ([#853](https://github.com/norman/friendly_id/pull/853)).
|
|
40
|
+
* Defer loading of ActiveRecord to avoid config issues. ([#852](https://github.com/norman/friendly_id/pull/852)).
|
|
41
|
+
* Ensure compatibility with paranoid deletion libraries. ([#838](https://github.com/norman/friendly_id/pull/838)).
|
|
42
|
+
* Add treat_reserved_as_conflict option to initializer ([#847](https://github.com/norman/friendly_id/pull/847)).
|
|
43
|
+
|
|
44
|
+
## 5.2.3 (2017-09-22)
|
|
45
|
+
|
|
46
|
+
* Added option to treat reserved words as conflicts ([#831](https://github.com/norman/friendly_id/pull/831)).
|
|
47
|
+
|
|
6
48
|
## 5.2.2 (2017-09-13)
|
|
7
49
|
|
|
8
50
|
* Prevent warning on db:migrate in Rails 5.1 ([#826](https://github.com/norman/friendly_id/pull/826)).
|
|
@@ -24,7 +66,7 @@ suggestions, ideas and improvements to FriendlyId.
|
|
|
24
66
|
* Don't calculate all changes just to check if the param field has changed ([#667](https://github.com/norman/friendly_id/pull/667)).
|
|
25
67
|
* Don't set or change slug when unrelated validation failures block the record from being saved ([#642](https://github.com/norman/friendly_id/issues/642)).
|
|
26
68
|
* Fix order dependence bug between history and finders modules ([#718](https://github.com/norman/friendly_id/pull/718))
|
|
27
|
-
* Added ability to conditionally turn off
|
|
69
|
+
* Added ability to conditionally turn off `:dependent => :destroy` on FriendlyId::Slugs([#724](https://github.com/norman/friendly_id/pull/724))
|
|
28
70
|
* Add support for Rails 5. ([#728](https://github.com/norman/friendly_id/pull/728))
|
|
29
71
|
* Allow per-model conditional disabling of friendly path generation using a :routes option to friendly_id ([#735](https://github.com/norman/friendly_id/pull/735))
|
|
30
72
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
[](https://github.com/norman/friendly_id/actions)
|
|
2
2
|
[](https://codeclimate.com/github/norman/friendly_id)
|
|
3
|
-
[ using the
|
|
9
|
-
"friendly-id" tag. Prior to asking, search and see if your question has
|
|
10
|
-
already been answered.
|
|
11
|
-
|
|
12
|
-
Please only post issues in Github issues for actual bugs.
|
|
13
|
-
|
|
14
|
-
I am asking people to do this because the same questions keep getting asked
|
|
15
|
-
over and over and over again in the issues.
|
|
3
|
+
[](https://inch-ci.org/github/norman/friendly_id)
|
|
16
4
|
|
|
17
5
|
# FriendlyId
|
|
18
6
|
|
|
19
|
-
**For the most complete, user-friendly documentation, see the [FriendlyId Guide](
|
|
7
|
+
**For the most complete, user-friendly documentation, see the [FriendlyId Guide](https://norman.github.io/friendly_id/file.Guide.html).**
|
|
20
8
|
|
|
21
9
|
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
|
|
22
10
|
Active Record. It lets you create pretty URLs and work with human-friendly
|
|
@@ -24,197 +12,102 @@ strings as if they were numeric ids.
|
|
|
24
12
|
|
|
25
13
|
With FriendlyId, it's easy to make your application use URLs like:
|
|
26
14
|
|
|
27
|
-
|
|
15
|
+
https://example.com/states/washington
|
|
28
16
|
|
|
29
17
|
instead of:
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## FriendlyId Features
|
|
35
|
-
|
|
36
|
-
FriendlyId offers many advanced features, including: slug history and
|
|
37
|
-
versioning, i18n, scoped slugs, reserved words, and custom slug generators.
|
|
38
|
-
|
|
39
|
-
### What Changed in Version 5.1
|
|
40
|
-
|
|
41
|
-
5.1 is a bugfix release, but bumps the minor version because some applications may be dependent
|
|
42
|
-
on the previously buggy behavior. The changes include:
|
|
43
|
-
|
|
44
|
-
* Blank strings can no longer be used as slugs.
|
|
45
|
-
* When the first slug candidate is rejected because it is reserved, additional candidates will
|
|
46
|
-
now be considered before marking the record as invalid.
|
|
47
|
-
* The `:finders` module is now compatible with Rails 4.2.
|
|
48
|
-
|
|
49
|
-
### What Changed in Version 5.0
|
|
50
|
-
|
|
51
|
-
As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
|
|
52
|
-
infer from the version number, 5.0 introduces changes incompatible with 4.0.
|
|
53
|
-
|
|
54
|
-
The most important changes are:
|
|
55
|
-
|
|
56
|
-
* Finders are no longer overridden by default. If you want to do friendly finds,
|
|
57
|
-
you must do `Model.friendly.find` rather than `Model.find`. You can however
|
|
58
|
-
restore FriendlyId 4-style finders by using the `:finders` addon:
|
|
59
|
-
|
|
60
|
-
```ruby
|
|
61
|
-
friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
|
|
62
|
-
# or...
|
|
63
|
-
friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
|
|
64
|
-
```
|
|
65
|
-
* A new "candidates" functionality which makes it easy to set up a list of
|
|
66
|
-
alternate slugs that can be used to uniquely distinguish records, rather than
|
|
67
|
-
appending a sequence. For example:
|
|
68
|
-
|
|
69
|
-
```ruby
|
|
70
|
-
class Restaurant < ActiveRecord::Base
|
|
71
|
-
extend FriendlyId
|
|
72
|
-
friendly_id :slug_candidates, use: :slugged
|
|
73
|
-
|
|
74
|
-
# Try building a slug based on the following fields in
|
|
75
|
-
# increasing order of specificity.
|
|
76
|
-
def slug_candidates
|
|
77
|
-
[
|
|
78
|
-
:name,
|
|
79
|
-
[:name, :city],
|
|
80
|
-
[:name, :street, :city],
|
|
81
|
-
[:name, :street_number, :street, :city]
|
|
82
|
-
]
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
```
|
|
86
|
-
* Now that candidates have been added, FriendlyId no longer uses a numeric
|
|
87
|
-
sequence to differentiate conflicting slug, but rather a UUID (e.g. something
|
|
88
|
-
like `2bc08962-b3dd-4f29-b2e6-244710c86106`). This makes the
|
|
89
|
-
codebase simpler and more reliable when running concurrently, at the expense
|
|
90
|
-
of uglier ids being generated when there are conflicts.
|
|
91
|
-
* The default sequence separator has been changed from two dashes to one dash.
|
|
92
|
-
* Slugs are no longer regenerated when a record is saved. If you want to regenerate
|
|
93
|
-
a slug, you must explicitly set the slug column to nil:
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
restaurant.friendly_id # joes-diner
|
|
97
|
-
restaurant.name = "The Plaza Diner"
|
|
98
|
-
restaurant.save!
|
|
99
|
-
restaurant.friendly_id # joes-diner
|
|
100
|
-
restaurant.slug = nil
|
|
101
|
-
restaurant.save!
|
|
102
|
-
restaurant.friendly_id # the-plaza-diner
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
You can restore some of the old behavior by overriding the
|
|
106
|
-
`should_generate_new_friendly_id?` method.
|
|
107
|
-
* The `friendly_id` Rails generator now generates an initializer showing you
|
|
108
|
-
how to do some common global configuration.
|
|
109
|
-
* The Globalize plugin has moved to a [separate gem](https://github.com/norman/friendly_id-globalize) (currently in alpha).
|
|
110
|
-
* The `:reserved` module no longer includes any default reserved words.
|
|
111
|
-
Previously it blocked "edit" and "new" everywhere. The default word list has
|
|
112
|
-
been moved to `config/initializers/friendly_id.rb` and now includes many more
|
|
113
|
-
words.
|
|
114
|
-
* The `:history` and `:scoped` addons can now be used together.
|
|
115
|
-
* Since it now requires Rails 4, FriendlyId also now requires Ruby 1.9.3 or
|
|
116
|
-
higher.
|
|
117
|
-
|
|
118
|
-
#### Upgrading from FriendlyId 4.0
|
|
119
|
-
|
|
120
|
-
Run `rails generate friendly_id --skip-migration` and edit the initializer
|
|
121
|
-
generated in `config/initializers/friendly_id.rb`. This file contains notes
|
|
122
|
-
describing how to restore (or not) some of the defaults from FriendlyId 4.0.
|
|
123
|
-
|
|
124
|
-
If you want to use the `:history` and `:scoped` addons together, you must add a
|
|
125
|
-
`:scope` column to your friendly_id_slugs table and replace the unique index on
|
|
126
|
-
`:slug` and `:sluggable_type` with a unique index on those two columns, plus
|
|
127
|
-
the new `:scope` column.
|
|
128
|
-
|
|
129
|
-
A migration like this should be sufficient:
|
|
130
|
-
|
|
131
|
-
```ruby
|
|
132
|
-
add_column :friendly_id_slugs, :scope, :string
|
|
133
|
-
remove_index :friendly_id_slugs, [:slug, :sluggable_type]
|
|
134
|
-
add_index :friendly_id_slugs, [:slug, :sluggable_type]
|
|
135
|
-
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
|
|
136
|
-
```
|
|
19
|
+
https://example.com/states/4323454
|
|
137
20
|
|
|
138
|
-
## Articles
|
|
139
21
|
|
|
140
|
-
|
|
141
|
-
[Pretty URLs with FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid)
|
|
22
|
+
## Getting Help
|
|
142
23
|
|
|
143
|
-
|
|
24
|
+
Ask questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/friendly-id)
|
|
25
|
+
using the "friendly-id" tag, and for bugs have a look at [the bug section](https://github.com/norman/friendly_id#bugs)
|
|
144
26
|
|
|
145
|
-
|
|
146
|
-
[here](http://norman.github.io/friendly_id).
|
|
27
|
+
## FriendlyId Features
|
|
147
28
|
|
|
148
|
-
|
|
29
|
+
FriendlyId offers many advanced features, including:
|
|
149
30
|
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
31
|
+
* slug history and versioning
|
|
32
|
+
* i18n
|
|
33
|
+
* scoped slugs
|
|
34
|
+
* reserved words
|
|
35
|
+
* custom slug generators
|
|
154
36
|
|
|
155
|
-
|
|
156
|
-
[Guide](http://norman.github.io/friendly_id/file.Guide.html),
|
|
157
|
-
which compiles the top-level RDocs into one outlined document.
|
|
37
|
+
## Usage
|
|
158
38
|
|
|
159
|
-
|
|
39
|
+
Add this line to your application's Gemfile:
|
|
160
40
|
|
|
161
|
-
|
|
162
|
-
|
|
41
|
+
```ruby
|
|
42
|
+
gem 'friendly_id', '~> 5.4.0'
|
|
43
|
+
```
|
|
163
44
|
|
|
45
|
+
Note: You MUST use 5.0.0 or greater for Rails 4.0+.
|
|
164
46
|
|
|
165
|
-
|
|
47
|
+
And then execute:
|
|
166
48
|
|
|
167
49
|
```shell
|
|
168
|
-
|
|
169
|
-
cd my_app
|
|
50
|
+
bundle install
|
|
170
51
|
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
52
|
+
|
|
53
|
+
Add a `slug` column to the desired table (e.g. `Users`)
|
|
54
|
+
```shell
|
|
55
|
+
rails g migration AddSlugToUsers slug:uniq
|
|
174
56
|
```
|
|
57
|
+
|
|
58
|
+
Generate the friendly configuration file and a new migration
|
|
59
|
+
|
|
175
60
|
```shell
|
|
176
61
|
rails generate friendly_id
|
|
177
62
|
```
|
|
178
|
-
|
|
179
|
-
`
|
|
63
|
+
|
|
64
|
+
Note: 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))
|
|
65
|
+
|
|
66
|
+
Run the migration scripts
|
|
67
|
+
|
|
180
68
|
```shell
|
|
181
|
-
rails
|
|
182
|
-
rake db:migrate
|
|
69
|
+
rails db:migrate
|
|
183
70
|
```
|
|
71
|
+
|
|
72
|
+
Edit the `app/models/user.rb` file as the following:
|
|
73
|
+
|
|
184
74
|
```ruby
|
|
185
|
-
# edit app/models/user.rb
|
|
186
75
|
class User < ApplicationRecord
|
|
187
76
|
extend FriendlyId
|
|
188
77
|
friendly_id :name, use: :slugged
|
|
189
78
|
end
|
|
79
|
+
```
|
|
190
80
|
|
|
191
|
-
User.
|
|
81
|
+
Edit the `app/controllers/users_controller.rb` file and replace `User.find` by `User.friendly.find`
|
|
192
82
|
|
|
193
|
-
|
|
194
|
-
|
|
83
|
+
```ruby
|
|
84
|
+
class UserController < ApplicationController
|
|
85
|
+
def show
|
|
86
|
+
@user = User.friendly.find(params[:id])
|
|
87
|
+
end
|
|
88
|
+
end
|
|
195
89
|
```
|
|
196
|
-
```shell
|
|
197
|
-
rails server
|
|
198
90
|
|
|
199
|
-
|
|
200
|
-
|
|
91
|
+
Now when you create a new user like the following:
|
|
92
|
+
|
|
201
93
|
```ruby
|
|
202
|
-
|
|
203
|
-
# to generate slugs for existing users, do this from the
|
|
204
|
-
# console, runner, or add a Rake task:
|
|
205
|
-
User.find_each(&:save)
|
|
94
|
+
User.create! name: "Joe Schmoe"
|
|
206
95
|
```
|
|
207
96
|
|
|
208
|
-
|
|
97
|
+
You can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.
|
|
209
98
|
|
|
210
|
-
The latest benchmarks for FriendlyId are maintained
|
|
211
|
-
[here](http://bit.ly/friendly-id-benchmarks).
|
|
212
99
|
|
|
100
|
+
If you're adding FriendlyId to an existing app and need to generate slugs for
|
|
101
|
+
existing users, do this from the console, runner, or add a Rake task:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
User.find_each(&:save)
|
|
105
|
+
```
|
|
213
106
|
|
|
214
107
|
## Bugs
|
|
215
108
|
|
|
216
109
|
Please report them on the [Github issue
|
|
217
|
-
tracker](
|
|
110
|
+
tracker](https://github.com/norman/friendly_id/issues) for this project.
|
|
218
111
|
|
|
219
112
|
If you have a bug to report, please include the following information:
|
|
220
113
|
|
|
@@ -226,8 +119,8 @@ If you have a bug to report, please include the following information:
|
|
|
226
119
|
If you are able to, it helps even more if you can fork FriendlyId on Github,
|
|
227
120
|
and add a test that reproduces the error you are experiencing.
|
|
228
121
|
|
|
229
|
-
For more
|
|
230
|
-
article](
|
|
122
|
+
For more inspiration on how to report bugs, please see [this
|
|
123
|
+
article](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
|
|
231
124
|
|
|
232
125
|
## Thanks and Credits
|
|
233
126
|
|
|
@@ -240,7 +133,7 @@ volunteers](https://github.com/norman/friendly_id/contributors).
|
|
|
240
133
|
|
|
241
134
|
## License
|
|
242
135
|
|
|
243
|
-
Copyright (c) 2008-
|
|
136
|
+
Copyright (c) 2008-2020 Norman Clarke and contributors, released under the MIT
|
|
244
137
|
license.
|
|
245
138
|
|
|
246
139
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|