I had a lot of trouble trying to get one of my Rails apps to accomplish this common task. For one thing, my dev box runs Windows 7, which notoriously does not play nicely with Ruby on Rails. Another thing... all the instructions/tutorials/document for the gem I'm using, Wicked PDF, were either incomplete or, for some reason or another, didn't work for me.
That's all to say, here are the steps I took, and I hope they will help someone.
I used the Wicked PDF gem. Ryan Bates over at RailsCasts goes over using PDFKit, but this writeup will be all about Wicked PDF.
These next steps I got straight from the instructions on the GitHub page: