Question

Curious as to why friendly_id encourage 2 dashes, instead of one?

Am interested why this is the default logic. Any reason why they chose two dashes, instead of one?

Was it helpful?

Solution

I thought about this recently and tried to change the sequence separator to 1 dash and FriendlyId complained, apparently for a valid reason.

This link doesn't answer your question exactly: https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L87-92

However, there's a tiny bit more info here: https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L293-305

I also saw that when I was using the history module, and performing a create, it checks for more recent slugs by appending a the sequence separator to the end.

eg:

Category.create(:name => 'foo')

returned the following sql queries

(0.1ms)  BEGIN
FriendlyId::Slug Load (49.9ms)  SELECT "friendly_id_slugs".* FROM "friendly_id_slugs" WHERE "friendly_id_slugs"."sluggable_type" = 'Category' AND (slug = 'foo' OR slug LIKE 'foo--%') ORDER BY LENGTH(slug) DESC, slug DESC LIMIT 1

If you changed the sequence separator to 1 dash, it would match items with slugs like 'foo-bar' and 'foo-moo' etc ...

Hope this helps satisfy your curiosity :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top