title: Ruby on Rails: How to override the 'show' route of a resource?
body: <p>Currently I have a route that looks like this:</p>
  
  <pre><code>resources :posts
  </code></pre>
  
  <p>I want to override the 'show' action so that I can display a url like this:</p>
  
  <pre><code>posts/:id/:slug
  </code></pre>
  
  <p>I am currently able to do this by adding a custom <code>match</code> route:</p>
  
  <pre><code>resources :posts
  match 'posts/:id/:slug' =&gt; 'posts#show'
  </code></pre>
  
  <p>However, when I use the <code>link_to</code> helper, it does not use my custom show route.</p>
  
  <pre><code>&lt;%= link_to 'show', post %&gt;  # renders /posts/123
  </code></pre>
  
  <p>How can I define my show route so that I can still use the <code>link_to</code> helper?</p>
  
  <p><strong>Update:</strong> As you can read in the following answers, you can override the route to the 'show' action, but it's probably more work than it's worth. It's easier to just create a custom route:</p>
  
  <pre><code># config/routes.rb
  match 'posts/:id/:slug' =&gt; 'posts#show', as: 'post_seo'
  
  # app/views/posts/index.html.erb
  &lt;%= link_to post.title, post_seo_path(post.id, post.slug) %&gt;
  </code></pre>