RSSAmplifier

Andy Croll · Mar 2, 2026

Customize Model URLs with to_param

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Rails models default to using their ID in URLs: /articles/42 . The to_param method lets you customize this—use a slug, hide the ID, or combine both for readable URLs. Exposing IDs isn’t dangerous if you scope access properly, but you might want cleaner paths. Instead of… …exposing IDs in your URLs: redirect_to article_path ( @article ) # => "/articles/42" Use… …the to_param method to return a slug…

Read on andycroll.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.