Adapted URL formatter from railscasts 301