Skip to content

Commit

Permalink
Document some common issues with slugs.
Browse files Browse the repository at this point in the history
This pertains to issues #180 and #185
  • Loading branch information
norman committed Dec 15, 2011
1 parent 1c31d49 commit c717fb9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/friendly_id/slugged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ def should_generate_new_friendly_id?
movie.slug #=> "der-preis-fuers-ueberleben"
This functionality was in fact taken from earlier versions of FriendlyId.
==== Common Problems
FriendlyId uses a before_validation callback to generate and set the slug. This
means that if you create two model instances before saving them, it's possible
they will generate the same slug, and the second save will fail.
This can happen in two fairly normal cases: the first, when a model using nested
attributes creates more than one record for a model that uses friendly_id. The
second, in concurrent code, either in threads or multiple processes.
To solve the nested attributes issue, I recommend simply avoiding them when
creating more than one nested record for a model that uses FriendlyId. See {this
Github issue}[https://github.com/norman/friendly_id/issues/185] for discussion.
To solve the concurrency issue, I recommend locking the model's table against
inserts while when saving the record. See {this Github
issue}[https://github.com/norman/friendly_id/issues/180] for discussion.
=end
module Slugged

Expand Down

0 comments on commit c717fb9

Please # to comment.