@@ -205,6 +205,32 @@ the same purpose of the named scope and returns and
205
205
` ActiveRecord::Relation` object.
206
206
* Beware of the behavior of the ` update_attribute` method. It doesn' t
207
207
run the model validations (unlike `update_attributes`) and could easily corrupt the model state.
208
+ * Use user-friendly URLs. Show some descriptive attribute of the model in the URL rather than its `id`.
209
+ There is more than one way to achieve this:
210
+ * Override the `to_param` method of the model. This method is used by Rails for constructing an URL to the object.
211
+ The default implementation returns the `id` of the record as a String. It could be overridden to include another
212
+ human-readable attribute.
213
+
214
+ ```Ruby
215
+ class Person
216
+ def to_param
217
+ "#{id} #{name}".parameterize
218
+ end
219
+ end
220
+ ```
221
+ In order to convert this to a URL-friendly value, `parameterize` should be called on the string. The `id` of the
222
+ object needs to be at the beginning so that it could be found by the `find` method of ActiveRecord.
223
+
224
+ * Use the `friendly_id` gem. It allows creation of human-readable URLs by using some descriptive attribute of the model instead of its `id`.
225
+
226
+ ```Ruby
227
+ class Person
228
+ extend FriendlyId
229
+ friendly_id :name, use: :slugged
230
+ end
231
+ ```
232
+
233
+ Check the [gem documentation](https://github.com/norman/friendly_id) for more information about its usage.
208
234
209
235
## Migrations
210
236
@@ -477,6 +503,8 @@ compatible with Ruby 1.9. Generates great reports. Must have!
477
503
* [active_admin](https://github.com/gregbell/active_admin) - With ActiveAdmin the creation of admin interface
478
504
for your Rails app is child's play. You get a nice dashboard, CRUD
479
505
UI and lots more. Very flexible and customizable.
506
+ * [friendly_id](https://github.com/norman/friendly_id) - Allows creation of human-readable URLs by using some
507
+ descriptive attribute of the model instead of its id.
480
508
481
509
This list is not exhaustive and other gems might be added to it along
482
510
the road. All of the gems on the list are field tested, have active
0 commit comments