I have a simple question: Slugify via helper or store the slug on database?

I mean, let's suppose that I have Guilherme Oderdenge on database and I want to transform it into a human-readable URL such as http://myapp.com/guilherme-oderdenge/, what's the best way to perform this? Storing guilherme-oderdenge in the database or transforming Guilherme Oderdenge in a slug with a helper like user.name.slugify?

I know there are some ways to reach the expected result, but which one is better? Or at least there is a better way?

It depends of the technology that you're using

I'm using Ruby On Rails with MySQL.

  • what do slug / slugify mean? – gnat Mar 6 '14 at 15:30
  • I really want to know about -1. – Guilherme Oderdenge Mar 6 '14 at 16:24
  • 3
    @gnat its what they call making a human readable but still valid URLs. So instead of a url like "/article/blog?id=3534546", it'd be "/article/gnats_blog" – GrandmasterB Mar 6 '14 at 17:13

I would store the slug in the database, this gives you the flexibility of being able to customize your slug if the logic to create a slug didn't create a desirable slug.

Also, if you had 2 pages with the same name, you would want to have two different slugs as they probably should be unique.

Thirdly this represents a good separation of concerns, the database if for querying data, not creating content.

Just to clarify, I recommend you create the slug in your app code, and store that in the db.

  • Perfect explanation and you convinced me. Thank you, that's enough for now. – Guilherme Oderdenge Mar 6 '14 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.