Slugify via helper or store slug on database?
https://softwareengineering.stackexchange.com/questions/231483
문제
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.
해결책
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.