title: How can I make rails route helpers always use to_param to generate the path, even when I just pass in an ActiveRecord ID?
body: <p>So, I'm implementing a pretty/SEO-friendly URL scheme for my rails app.  I have a model called Artist, and I would like the Rails <code>artist_path</code> helper to always generate the friendly version of the path.</p>
  
  <p>In my routes.rb file, I have the following line:</p>
  
  <pre><code>  get 'artists/:id(/:slug)', :to =&gt; 'artists#show', :as =&gt; 'artist'
  </code></pre>
  
  <p>If the slug is left out, or is incorrect (it's calculated by the artist name), the controller 301 redirects to the correct URL.  However, for SEO reasons, I want to ensure that all links internal to my site have the correct URL to start with.</p>
  
  <p>The Artist model has the two following (very simple) functions to allow this to work:</p>
  
  <pre><code>  def slug
      name.parameterize
    end
  
    def to_param
      "#{id}/#{slug}"
    end
  </code></pre>
  
  <p>If I call <code>artist_path</code> with an artist object, this works as intended:</p>
  
  <pre><code>&gt; app.artist_path(Artist.find 1234)
  =&gt; "/artists/1234/artist-name"
  </code></pre>
  
  <p>However, when I use call it with just the ID, it does not seem to use to_param at all:</p>
  
  <pre><code>&gt; app.artist_path(id: 1234)
  =&gt; "/artists/1234"
  </code></pre>
  
  <p>tl;dr: <strong>How can I force Rails to always instantiate the object and call <code>to_param</code> on it when <code>artist_path</code> is called, even when only the ID is specified?</strong></p>