Customize Model URLs with to_param

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…