Users want a custom URL for their profile. So instead of visiting /profiles/2
they can visit something like /profiles/Gustavo
.
There will need to be a new profile field to hold the custom “slug”
def change
add_column :profiles, :slug, :string
add_index :profiles, :slug, unique: true
end
The uniqueness is necessary because no two users should have the same slug. The unique index enforces uniqueness at the db level and gives better performance on reads.
We can roll our own system here. The profiles controller can look up a profile by a slug
field with code like:
Article.find_by!(slug: params[:id])
Pros
Cons