title: Rails route to username instead of id
body: <p>I am trying to change the rails routes from /users/1 to /username. I currently set this up so it works for the actions of showing and editing. The actual issue is that when I go to update the user by using:</p>
  
  <pre><code>&lt;%= form_for @user do |f|%&gt;
  </code></pre>
  
  <p>It never updates, because the update action is routed to /users/:id. Is there any way to route this so that it works for /username? (which is the route that is rendering in my forms as the action). I've been scratching my head over this one for a while now.</p>
  
  <p>EDIT:</p>
  
  <p>The issue isn't routing to username, that it working correctly. The issue is that the form routes to /username for update, however the update route for users is still /users/:id instead of :/id.</p>
  
  <p>I tried updating my routes to this, but to no avail:</p>
  
  <pre><code>match '/:id', :to =&gt; "users#show", :as =&gt; :user
  match '/:id', :to =&gt; "users#update", :as =&gt; :user, :via =&gt; :put
  match '/:id', :to =&gt; "users#destroy", :as =&gt; :user, :via =&gt; :delete
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Doh! This fixed the issue:</p>
  
  <pre><code>match '/:id', :to =&gt; "users#show", :as =&gt; :user, :via =&gt; :get
  </code></pre>