ultra-clean-lib 0.0.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 +7 -0
- data/friendly_id-5.7.0/Changelog.md +273 -0
- data/friendly_id-5.7.0/MIT-LICENSE +19 -0
- data/friendly_id-5.7.0/README.md +176 -0
- data/friendly_id-5.7.0/lib/friendly_id/base.rb +275 -0
- data/friendly_id-5.7.0/lib/friendly_id/candidates.rb +71 -0
- data/friendly_id-5.7.0/lib/friendly_id/configuration.rb +111 -0
- data/friendly_id-5.7.0/lib/friendly_id/finder_methods.rb +123 -0
- data/friendly_id-5.7.0/lib/friendly_id/finders.rb +92 -0
- data/friendly_id-5.7.0/lib/friendly_id/history.rb +146 -0
- data/friendly_id-5.7.0/lib/friendly_id/initializer.rb +107 -0
- data/friendly_id-5.7.0/lib/friendly_id/migration.rb +21 -0
- data/friendly_id-5.7.0/lib/friendly_id/object_utils.rb +76 -0
- data/friendly_id-5.7.0/lib/friendly_id/reserved.rb +50 -0
- data/friendly_id-5.7.0/lib/friendly_id/scoped.rb +175 -0
- data/friendly_id-5.7.0/lib/friendly_id/sequentially_slugged/calculator.rb +69 -0
- data/friendly_id-5.7.0/lib/friendly_id/sequentially_slugged.rb +40 -0
- data/friendly_id-5.7.0/lib/friendly_id/simple_i18n.rb +114 -0
- data/friendly_id-5.7.0/lib/friendly_id/slug.rb +16 -0
- data/friendly_id-5.7.0/lib/friendly_id/slug_generator.rb +38 -0
- data/friendly_id-5.7.0/lib/friendly_id/slugged.rb +436 -0
- data/friendly_id-5.7.0/lib/friendly_id/version.rb +3 -0
- data/friendly_id-5.7.0/lib/friendly_id.rb +114 -0
- data/friendly_id-5.7.0/lib/generators/friendly_id_generator.rb +26 -0
- data/ultra-clean-lib.gemspec +12 -0
- metadata +65 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 07accc5efdc4f5c59cb0c82d5abf3c10c06c7c0cb8c6f90d30b2f43fd5f0b8b2
|
|
4
|
+
data.tar.gz: 6836b8bbeddc390d2646e77dd7a812729f0e5618541360d3273acd6f567caccb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8830450cef1b470489e0c46ef272212dde15f78997b3af3407015f7d06634c54cc17e21962afafedab0103afee8d8b270812b9a7ba2cddaa63142850edf3935b
|
|
7
|
+
data.tar.gz: 37455d17655a7924bb25e4a8fdc810d5f4c6cb1822554f186a153d936ffd94192ea5f146eb1880ced5762fe073a209412eeaa6b9f73d08f5cb643df2e656047a
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# FriendlyId Changelog
|
|
2
|
+
|
|
3
|
+
We would like to think our many [contributors](https://github.com/norman/friendly_id/graphs/contributors) for
|
|
4
|
+
suggestions, ideas and improvements to FriendlyId.
|
|
5
|
+
|
|
6
|
+
## 5.6.0 (2025-12-07)
|
|
7
|
+
|
|
8
|
+
* Add: `treat_numeric_as_conflict` option to prevent ambiguous numeric slugs. ([#1037](https://github.com/norman/friendly_id/pull/1037))
|
|
9
|
+
* Fix: history not using `parse_friendly_id`. ([#1020](https://github.com/norman/friendly_id/pull/1020))
|
|
10
|
+
|
|
11
|
+
## 5.5.1 (2023-11-13)
|
|
12
|
+
|
|
13
|
+
* Fix YARD doc generation. ([#1006](https://github.com/norman/friendly_id/pull/1006))
|
|
14
|
+
|
|
15
|
+
## 5.5.0 (2022-11-16)
|
|
16
|
+
|
|
17
|
+
* SimpleI18n: Handle regional locales ([#965](https://github.com/norman/friendly_id/pull/965))
|
|
18
|
+
* Fix: "unknown column" exception ([#943](https://github.com/norman/friendly_id/pull/943))
|
|
19
|
+
* Add: `allow_nil: true` to the Finder ([#995](https://github.com/norman/friendly_id/pull/995) and [#997](https://github.com/norman/friendly_id/pull/997))
|
|
20
|
+
|
|
21
|
+
## 5.4.2 (2021-01-07)
|
|
22
|
+
|
|
23
|
+
* Fix: Set slug before save if needed ([#948](https://github.com/norman/friendly_id/pull/948))
|
|
24
|
+
* Revert "Make `first_by_friendly_id` case insensitive using `downcase`" ([#951](https://github.com/norman/friendly_id/pull/951))
|
|
25
|
+
|
|
26
|
+
## 5.4.1 (2020-11-06)
|
|
27
|
+
|
|
28
|
+
* Fix unexpected `:slug` error on valid, unpersisted model ([#952](https://github.com/norman/friendly_id/pull/952))
|
|
29
|
+
|
|
30
|
+
## 5.4.0 (2020-08-14)
|
|
31
|
+
|
|
32
|
+
* Fix Ruby 2.7 keyword params deprecation warning ([#939](https://github.com/norman/friendly_id/pull/939))
|
|
33
|
+
* Fix Slug Validation in `unset_slug_if_invalid` ([#938](https://github.com/norman/friendly_id/pull/938))
|
|
34
|
+
* Make `first_by_friendly_id` case insensitive using `downcase` ([#787](https://github.com/norman/friendly_id/pull/787))
|
|
35
|
+
* Use `destroy_all` rather than `delete_all` when creating historical slugs ([#924](https://github.com/norman/friendly_id/pull/924))
|
|
36
|
+
* Set required ruby version to `>= 2.1.0` ([#923](https://github.com/norman/friendly_id/pull/923))
|
|
37
|
+
* Avoid using deprecated `update_attributes` ([#922](https://github.com/norman/friendly_id/pull/922))
|
|
38
|
+
|
|
39
|
+
## 5.3.0 (2019-09-25)
|
|
40
|
+
|
|
41
|
+
* Record history when scope changes but slug does not ([#916](https://github.com/norman/friendly_id/pull/916))
|
|
42
|
+
* Add support for Rails 6 ([#897](https://github.com/norman/friendly_id/pull/897))
|
|
43
|
+
|
|
44
|
+
## 5.2.5 (2018-12-30)
|
|
45
|
+
|
|
46
|
+
* Pass all possible parameters to ActiveRecord::RecordNotFound.new when raising the exception ([#890](https://github.com/norman/friendly_id/pull/890))
|
|
47
|
+
* Use composite index for queries by sluggable ([#882](https://github.com/norman/friendly_id/pull/882))
|
|
48
|
+
* Scoped: generate new slug if scope changed ([#878](https://github.com/norman/friendly_id/pull/878))
|
|
49
|
+
* Fix History + SequentiallySlugged issues ([#877](https://github.com/norman/friendly_id/pull/877))
|
|
50
|
+
* Support scoped with STI ([#745](https://github.com/norman/friendly_id/pull/745))
|
|
51
|
+
* Fix exists? to behave the same as find for numeric slugs ([#875](https://github.com/norman/friendly_id/pull/875))
|
|
52
|
+
* Remove dirty tracking code from to_param ([#867](https://github.com/norman/friendly_id/pull/867))
|
|
53
|
+
|
|
54
|
+
## 5.2.4 (2018-04-24)
|
|
55
|
+
|
|
56
|
+
* Fix compatibility with Rails versions 4.0 -> 5.2. ([#863](https://github.com/norman/friendly_id/pull/863)).
|
|
57
|
+
* Refactor `History::FinderMethods` to use base implementation. ([#853](https://github.com/norman/friendly_id/pull/853)).
|
|
58
|
+
* Defer loading of ActiveRecord to avoid config issues. ([#852](https://github.com/norman/friendly_id/pull/852)).
|
|
59
|
+
* Ensure compatibility with paranoid deletion libraries. ([#838](https://github.com/norman/friendly_id/pull/838)).
|
|
60
|
+
* Add treat_reserved_as_conflict option to initializer ([#847](https://github.com/norman/friendly_id/pull/847)).
|
|
61
|
+
|
|
62
|
+
## 5.2.3 (2017-09-22)
|
|
63
|
+
|
|
64
|
+
* Added option to treat reserved words as conflicts ([#831](https://github.com/norman/friendly_id/pull/831)).
|
|
65
|
+
|
|
66
|
+
## 5.2.2 (2017-09-13)
|
|
67
|
+
|
|
68
|
+
* Prevent warning on db:migrate in Rails 5.1 ([#826](https://github.com/norman/friendly_id/pull/826)).
|
|
69
|
+
* Allow to set size limit for slug ([#809](https://github.com/norman/friendly_id/pull/809)).
|
|
70
|
+
* Update specs and drop support for ruby 2.0.0 ([#824](https://github.com/norman/friendly_id/pull/824)).
|
|
71
|
+
|
|
72
|
+
## 5.2.1 (2017-04-09)
|
|
73
|
+
|
|
74
|
+
* Change ActiveRecord::Base to ApplicationRecord ([#782](https://github.com/norman/friendly_id/pull/782)).
|
|
75
|
+
* Refactor `Candidates#each` method. ([#773](https://github.com/norman/friendly_id/pull/773)).
|
|
76
|
+
* Assign to configured slug column, not 'slug' when validation fails. ([#779](https://github.com/norman/friendly_id/pull/779)).
|
|
77
|
+
* Fix sequential slugs when using History. ([#774](https://github.com/norman/friendly_id/pull/774)).
|
|
78
|
+
|
|
79
|
+
## 5.2.0 (2016-12-01)
|
|
80
|
+
|
|
81
|
+
* Add sequential slug module for FriendlyId 4.x-style sequential slugs. ([#644](https://github.com/norman/friendly_id/pull/644)).
|
|
82
|
+
* Make Candidates#each iterable without block ([#651](https://github.com/norman/friendly_id/pull/651)).
|
|
83
|
+
* Ensure slug history prefers the record that most recently used the slug ([#663](https://github.com/norman/friendly_id/pull/663)).
|
|
84
|
+
* Don't calculate all changes just to check if the param field has changed ([#667](https://github.com/norman/friendly_id/pull/667)).
|
|
85
|
+
* 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)).
|
|
86
|
+
* Fix order dependence bug between history and finders modules ([#718](https://github.com/norman/friendly_id/pull/718))
|
|
87
|
+
* Added ability to conditionally turn off `:dependent => :destroy` on FriendlyId::Slugs([#724](https://github.com/norman/friendly_id/pull/724))
|
|
88
|
+
* Add support for Rails 5. ([#728](https://github.com/norman/friendly_id/pull/728))
|
|
89
|
+
* 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))
|
|
90
|
+
|
|
91
|
+
## 5.1.0 (2015-01-15)
|
|
92
|
+
|
|
93
|
+
* FriendlyId will no longer allow blank strings as slugs ([#571](https://github.com/norman/friendly_id/pull/571)).
|
|
94
|
+
* FriendlyId will now try to use the first non-reserved candidate as its
|
|
95
|
+
slug and will only mark the record invalid if all candidates ([#536](https://github.com/norman/friendly_id/issues/536)).
|
|
96
|
+
* Fix order dependence bug between history and scoped modules ([#588](https://github.com/norman/friendly_id/pull/588)).
|
|
97
|
+
* Fix "friendly" finds on Rails 4.2 ([#607](https://github.com/norman/friendly_id/issues/607)).
|
|
98
|
+
|
|
99
|
+
## 5.0.4 (2014-05-29)
|
|
100
|
+
|
|
101
|
+
* Bug fix for call to removed `primary` method on Edge Rails. ([#557](https://github.com/norman/friendly_id/pull/557)).
|
|
102
|
+
* Bug fix for unwanted slug regeneration when the slug source was changed, but not the actual generated slug ([#563](https://github.com/norman/friendly_id/pull/562)).
|
|
103
|
+
* Big fix to look for UUIDs only at the end of slugs ([#548](https://github.com/norman/friendly_id/pull/548)).
|
|
104
|
+
* Various documentation and test setup improvements.
|
|
105
|
+
|
|
106
|
+
## 5.0.3 (2013-02-14)
|
|
107
|
+
|
|
108
|
+
* Bug fix for calls to #dup with unslugged models ([#518](https://github.com/norman/friendly_id/pull/518)).
|
|
109
|
+
* Bug fixes for STI ([#516](https://github.com/norman/friendly_id/pull/516)).
|
|
110
|
+
* Bug fix for slug regeneration (both scoped and unscoped) ([#513](https://github.com/norman/friendly_id/pull/513)).
|
|
111
|
+
* Bug fix for finds with models that use the :history module ([#509](https://github.com/norman/friendly_id/pull/509)).
|
|
112
|
+
|
|
113
|
+
## 5.0.2 (2013-12-10)
|
|
114
|
+
|
|
115
|
+
* Query performance improvements ([#497](https://github.com/norman/friendly_id/pull/497)).
|
|
116
|
+
* Documentation improvements (thanks [John Bachir](https://github.com/jjb)).
|
|
117
|
+
* Minor refactoring of internals (thanks [Gagan Ahwad](https://github.com/gaganawhad)).
|
|
118
|
+
* Set slug to `nil` on call to `dup` to ensure slug is generated ([#483](https://github.com/norman/friendly_id/pull/483)).
|
|
119
|
+
|
|
120
|
+
## 5.0.1 (2013-10-27)
|
|
121
|
+
|
|
122
|
+
* Fix compatibility with Rails 4.0.1.rc3 (thanks [Herman verschooten](https://github.com/Hermanverschooten)).
|
|
123
|
+
|
|
124
|
+
## 5.0.0 (2013-10-16)
|
|
125
|
+
|
|
126
|
+
* Fix to let scoped records reuse their slugs (thanks [Donny
|
|
127
|
+
Kurnia](https://github.com/donnykurnia)).
|
|
128
|
+
|
|
129
|
+
## 5.0.0.rc.3 (2013-10-04)
|
|
130
|
+
|
|
131
|
+
* Support friendly finds on associations in Rails 4.0.1 and up. They will
|
|
132
|
+
currently work on Rails 4.0 associations only if `:inverse_of` is not used.
|
|
133
|
+
In Rails 4-0-stable, associations have been modified to use a special
|
|
134
|
+
relation class, giving FriendlyId a consistent extension point. Since the
|
|
135
|
+
behavior in 4.0.0 is considered defective and fixed in 4-0-stable, FriendlyId
|
|
136
|
+
5.0 will not support friendly finds on inverse relelations in 4.0.0. For a
|
|
137
|
+
reliable workaround, use the `friendly` scope for friendly finds on
|
|
138
|
+
associations; this works on all Rails 4.0.x versions and will continue to be
|
|
139
|
+
supported.
|
|
140
|
+
* Documentation fixes.
|
|
141
|
+
|
|
142
|
+
## 5.0.0.rc2 (2013-09-29)
|
|
143
|
+
|
|
144
|
+
* When the :finders addon has been included, use it in FriendlyId's internal
|
|
145
|
+
finds to boost performance.
|
|
146
|
+
* Use instance methods rather than class methods in migrations.
|
|
147
|
+
* On find, fall back to super when the primary key is a character type. Thanks
|
|
148
|
+
to [Jamie Davidson](https://github.com/jhdavids8).
|
|
149
|
+
* Fix reversion to previously used slug from history table when
|
|
150
|
+
`should_generate_new_friendly_id?` is overridden.
|
|
151
|
+
* Fix sequencing of numeric slugs
|
|
152
|
+
|
|
153
|
+
## 5.0.0.rc1 (2013-08-28)
|
|
154
|
+
|
|
155
|
+
* Removed some outdated tests.
|
|
156
|
+
* Improved documentation.
|
|
157
|
+
* Removed Guide from repository and added tasks to maintain docs up to date
|
|
158
|
+
on Github pages at http://norman.github.io/friendly_id.
|
|
159
|
+
|
|
160
|
+
## 5.0.0.beta4 (2013-08-21)
|
|
161
|
+
|
|
162
|
+
* Add an initializer to the generator; move the default reserved words there.
|
|
163
|
+
* Allow assignment from {FriendlyId::Configuration#base}.
|
|
164
|
+
* Fix bug whereby records could not reuse their own slugs.
|
|
165
|
+
|
|
166
|
+
## 5.0.0.beta3 (2013-08-20)
|
|
167
|
+
|
|
168
|
+
* Update gemspec to ensure FriendlyId 5.0 is only used with AR 4.0.x.
|
|
169
|
+
|
|
170
|
+
## 5.0.0.beta2 (2013-08-16)
|
|
171
|
+
|
|
172
|
+
* Add "finders" module to easily restore FriendlyId 4.0 finder behavior.
|
|
173
|
+
|
|
174
|
+
## 5.0.0.beta1 (2013-08-10)
|
|
175
|
+
|
|
176
|
+
* Support for Rails 4.
|
|
177
|
+
* Made the :scoped and :history modules compatible with each other (Andre Duffeck).
|
|
178
|
+
* Removed class-level finders in favor of `friendly` scope (Norman Clarke).
|
|
179
|
+
* Implemented "candidates" support (Norman Clarke).
|
|
180
|
+
* Slug "sequences" are now GUIDs rather than numbers (Norman Clarke).
|
|
181
|
+
* `find` no longer falls back to super unless id is fully numeric string (Norman Clarke).
|
|
182
|
+
* Default sequence separator is now '-' rather than '--'.
|
|
183
|
+
* Support for Globalize has been removed until Globalize supports Rails 4.
|
|
184
|
+
* Removed support for Ruby < 1.9.3 and Rails < 4.0.
|
|
185
|
+
|
|
186
|
+
## 4.0.10.1 (2013-08-20)
|
|
187
|
+
|
|
188
|
+
* Update dependencies in gemspec to avoid using with Active Record 4.
|
|
189
|
+
* Fixed links in docs.
|
|
190
|
+
|
|
191
|
+
## 4.0.10 (2013-08-10)
|
|
192
|
+
|
|
193
|
+
* Fixed table prefixes/suffixes being ignored (Jesse Farless).
|
|
194
|
+
* Fixed sequence generation for slugs containing numbers (Adam Carroll).
|
|
195
|
+
|
|
196
|
+
## 4.0.9 (2012-10-31)
|
|
197
|
+
|
|
198
|
+
* Fixed support for Rails 3.2.9.rc1
|
|
199
|
+
|
|
200
|
+
## 4.0.8 (2012-08-01)
|
|
201
|
+
|
|
202
|
+
* Name internal anonymous class to fix marshall dump/load error (Jess Brown, Philip Arndt and Norman Clarke).
|
|
203
|
+
|
|
204
|
+
* Avoid using deprecated `update_attribute` (Philip Arndt).
|
|
205
|
+
|
|
206
|
+
* Added set_friendly_id method to Globalize module (Norman Clarke).
|
|
207
|
+
|
|
208
|
+
* autoload FriendlyId::Slug; previously this class was not accessible from
|
|
209
|
+
migrations unless required explicitly, which could cause some queries to
|
|
210
|
+
unexpectedly fail (Norman Clarke).
|
|
211
|
+
|
|
212
|
+
* Fix Mocha load order (Mark Turner).
|
|
213
|
+
|
|
214
|
+
* Minor doc updates (Rob Yurkowski).
|
|
215
|
+
|
|
216
|
+
* Other miscellaneous refactorings and doc updates.
|
|
217
|
+
|
|
218
|
+
## 4.0.7 (2012-06-06)
|
|
219
|
+
|
|
220
|
+
* to_param just calls super when no friendly id is present, to keep the model's
|
|
221
|
+
default behavior. (Andrew White)
|
|
222
|
+
|
|
223
|
+
* FriendlyId can now properly sequence slugs that end in numbers even when a
|
|
224
|
+
single dash is used as the separator (Tomás Arribas).
|
|
225
|
+
|
|
226
|
+
## 4.0.6 (2012-05-21)
|
|
227
|
+
|
|
228
|
+
* Fix nil return value from to_param when save fails because of validation errors (Tomás Arribas)
|
|
229
|
+
* Fix incorrect usage of i18n API (Vinicius Ferriani)
|
|
230
|
+
* Improve error handling in reserved module (Adrián Mugnolo and Github user "nolamesa")
|
|
231
|
+
|
|
232
|
+
## 4.0.5 (2012-04-28)
|
|
233
|
+
|
|
234
|
+
* Favor `includes` over `joins` in globalize to avoid read-only results (Jakub Wojtysiak)
|
|
235
|
+
* Fix globalize compatibility with results from dynamic finders (Chris Salzberg)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
## 4.0.4 (2012-03-26)
|
|
239
|
+
|
|
240
|
+
* Fix globalize plugin to avoid issues with asset precompilation (Philip Arndt)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
## 4.0.3 (2012-03-14)
|
|
244
|
+
|
|
245
|
+
* Fix escape for '%' and '_' on SQLite (Norman Clarke and Sergey Petrunin)
|
|
246
|
+
* Allow FriendlyId to be extended or included (Norman Clarke)
|
|
247
|
+
* Allow Configuration#use to accept a Module (Norman Clarke)
|
|
248
|
+
* Fix bugs with History module + STI (Norman Clarke and Sergey Petrunin)
|
|
249
|
+
|
|
250
|
+
## 4.0.2 (2012-03-12)
|
|
251
|
+
|
|
252
|
+
* Improved conflict handling and performance in History module (Erik Ogan and Thomas Shafer)
|
|
253
|
+
* Fixed bug that impeded using underscores as a sequence separator (Erik Ogan and Thomas Shafer)
|
|
254
|
+
* Minor documentation improvements (Norman Clarke)
|
|
255
|
+
|
|
256
|
+
## 4.0.1 (2012-02-29)
|
|
257
|
+
|
|
258
|
+
* Added support for Globalize 3 (Enrico Pilotto and Philip Arndt)
|
|
259
|
+
* Allow the scoped module to use multiple scopes (Ben Caldwell)
|
|
260
|
+
* Fixes for conflicting slugs in history module (Erik Ogan, Thomas Shafer, Evan Arnold)
|
|
261
|
+
* Fix for conflicting slugs when using STI (Danny van der Heiden, Diederick Lawson)
|
|
262
|
+
* Maintainence improvements (Norman Clarke, Philip Arndt, Thomas Darde, Lee Hambley)
|
|
263
|
+
|
|
264
|
+
## 4.0.0 (2011-12-27)
|
|
265
|
+
|
|
266
|
+
This is a complete rewrite of FriendlyId, and introduces a smaller, faster and
|
|
267
|
+
less ambitious codebase. The primary change is the relegation of external slugs
|
|
268
|
+
to an optional addon, and the adoption of what were formerly "cached slugs"
|
|
269
|
+
as the primary way of handling slugging.
|
|
270
|
+
|
|
271
|
+
## Older releases
|
|
272
|
+
|
|
273
|
+
Please see the 3.x branch.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2008-2016 Norman Clarke, Adrian Mugnolo and Emilio Tagua.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
[](https://github.com/norman/friendly_id/actions)
|
|
2
|
+
[](https://codeclimate.com/github/norman/friendly_id)
|
|
3
|
+
[](https://inch-ci.org/github/norman/friendly_id)
|
|
4
|
+
|
|
5
|
+
# FriendlyId
|
|
6
|
+
|
|
7
|
+
**For the most complete, user-friendly documentation, see the [FriendlyId Guide](https://norman.github.io/friendly_id/file.Guide.html).**
|
|
8
|
+
|
|
9
|
+
FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
|
|
10
|
+
Active Record. It lets you create pretty URLs and work with human-friendly
|
|
11
|
+
strings as if they were numeric ids.
|
|
12
|
+
|
|
13
|
+
With FriendlyId, it's easy to make your application use URLs like:
|
|
14
|
+
|
|
15
|
+
https://example.com/states/washington
|
|
16
|
+
|
|
17
|
+
instead of:
|
|
18
|
+
|
|
19
|
+
https://example.com/states/4323454
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Getting Help
|
|
23
|
+
|
|
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)
|
|
26
|
+
|
|
27
|
+
## FriendlyId Features
|
|
28
|
+
|
|
29
|
+
FriendlyId offers many advanced features, including:
|
|
30
|
+
|
|
31
|
+
* slug history and versioning
|
|
32
|
+
* i18n
|
|
33
|
+
* scoped slugs
|
|
34
|
+
* reserved words
|
|
35
|
+
* custom slug generators
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
Add this line to your application's Gemfile:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
gem 'friendly_id', '~> 5.5.0'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Note: You MUST use 5.0.0 or greater for Rails 4.0+.
|
|
46
|
+
|
|
47
|
+
And then execute:
|
|
48
|
+
|
|
49
|
+
```shell
|
|
50
|
+
bundle install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Add a `slug` column to the desired table (e.g. `Users`)
|
|
54
|
+
```shell
|
|
55
|
+
rails g migration AddSlugToUsers slug:uniq
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Generate the friendly configuration file and a new migration
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
rails generate friendly_id
|
|
62
|
+
```
|
|
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
|
+
|
|
68
|
+
```shell
|
|
69
|
+
rails db:migrate
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Edit the `app/models/user.rb` file as the following:
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
class User < ApplicationRecord
|
|
76
|
+
extend FriendlyId
|
|
77
|
+
friendly_id :name, use: :slugged
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Edit the `app/controllers/users_controller.rb` file and replace `User.find` by `User.friendly.find`
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
class UserController < ApplicationController
|
|
85
|
+
def show
|
|
86
|
+
@user = User.friendly.find(params[:id])
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Now when you create a new user like the following:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
User.create! name: "Joe Schmoe"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
You can then access the user show page using the URL http://localhost:3000/users/joe-schmoe.
|
|
98
|
+
|
|
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
|
+
```
|
|
106
|
+
|
|
107
|
+
## Options
|
|
108
|
+
|
|
109
|
+
### `:allow_nil`
|
|
110
|
+
|
|
111
|
+
You can pass `allow_nil: true` to the `friendly.find()` method if you want to
|
|
112
|
+
avoid raising `ActiveRecord::RecordNotFound` and accept `nil`.
|
|
113
|
+
|
|
114
|
+
#### Example
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
MyModel.friendly.find("bad-slug") # where bad-slug is not a valid slug
|
|
118
|
+
MyModel.friendly.find(123) # where 123 is not a valid primary key ID
|
|
119
|
+
MyModel.friendly.find(nil) # maybe you have a variable/param that's potentially nil
|
|
120
|
+
#=> raise ActiveRecord::RecordNotFound
|
|
121
|
+
|
|
122
|
+
MyModel.friendly.find("bad-slug", allow_nil: true)
|
|
123
|
+
MyModel.friendly.find(123, allow_nil: true)
|
|
124
|
+
MyModel.friendly.find(nil, allow_nil: true)
|
|
125
|
+
#=> nil
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Bugs
|
|
129
|
+
|
|
130
|
+
Please report them on the [Github issue
|
|
131
|
+
tracker](https://github.com/norman/friendly_id/issues) for this project.
|
|
132
|
+
|
|
133
|
+
If you have a bug to report, please include the following information:
|
|
134
|
+
|
|
135
|
+
* **Version information for FriendlyId, Rails and Ruby.**
|
|
136
|
+
* Full stack trace and error message (if you have them).
|
|
137
|
+
* Any snippets of relevant model, view or controller code that shows how you
|
|
138
|
+
are using FriendlyId.
|
|
139
|
+
|
|
140
|
+
If you are able to, it helps even more if you can fork FriendlyId on Github,
|
|
141
|
+
and add a test that reproduces the error you are experiencing.
|
|
142
|
+
|
|
143
|
+
For more inspiration on how to report bugs, please see [this
|
|
144
|
+
article](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
|
|
145
|
+
|
|
146
|
+
## Thanks and Credits
|
|
147
|
+
|
|
148
|
+
FriendlyId was originally created by Norman Clarke and Adrian Mugnolo, with
|
|
149
|
+
significant help early in its life by Emilio Tagua. It is now maintained by
|
|
150
|
+
Norman Clarke and Philip Arndt.
|
|
151
|
+
|
|
152
|
+
We're deeply grateful for the generous contributions over the years from [many
|
|
153
|
+
volunteers](https://github.com/norman/friendly_id/contributors).
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
Copyright (c) 2008-2020 Norman Clarke and contributors, released under the MIT
|
|
158
|
+
license.
|
|
159
|
+
|
|
160
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
161
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
162
|
+
the Software without restriction, including without limitation the rights to
|
|
163
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
164
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
165
|
+
so, subject to the following conditions:
|
|
166
|
+
|
|
167
|
+
The above copyright notice and this permission notice shall be included in all
|
|
168
|
+
copies or substantial portions of the Software.
|
|
169
|
+
|
|
170
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
171
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
172
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
173
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
174
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
175
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
176
|
+
SOFTWARE.
|