Appendix B. Tidbits
This appendix contains a collection of tidbits that we just couldn’t fit into the rest of the book. They are designed to be read by themselves, although you are welcome (and encouraged!) to read as many of them at once as you wish.
In your application you’ve got a URL such as /projects/1/tickets/2, which really isn’t that pretty. Let’s take a look at how you can make the ticket’s ID part of these URLs a little prettier, turning them into something like /projects/1/tickets/2-make-it-shiny.
Having URLs such as /projects/1/tickets/2-make-it-shiny will allow your users to easily identify what that URL links to without having to visit the page.[1] Rails allows you to very easily do this by overriding a method called to_param in the model where you want to have pretty URLs. This method is defined like this within ActiveRecord::Base, and so all your models inherit it:
1 It’s also supposedly good for search engine optimization (SEO).
This method is used to construct the URLs generated by the link helpers in your application such as project_ticket_path, if you use them like this: