You know, like myblog.com/posts/donald-e-knuth.
Should I do this with the built in parameterize
method?
What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone have any experience with them?
Basically it seems like slugs are a totally solved problem, and I don't to reinvent the wheel.
Generating a slug to use in the URL and store it as an attribute in the database. Replace the ID by the generated slug in the Rails routing Helpers by overriding the method to_param in the models. Handle the request with the slug parameter in Controllers.
Slugs are a colloquial term for the “SEO-friendly” identifier part of a URL. Seen a lot in applications like blogs or public sites, they turn a URL like: https://blog.example.com/posts/123. into one like this: https://blog.example.com/posts/clickbait-teaser-goes-here.
In Rails you can use #parameterize
For example:
> "Foo bar`s".parameterize => "foo-bar-s"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With