title: Rails Routes With Query Parameters
body: <p>Not really sure the terminology involved, I didn't find anything searching but if someone can point me in the right direction I'll take another look.</p>
  
  <p>I have a controller called Journals.  I would like to have a date optionally part of the URL.  If the user doesn't specify a date, they get today.  If there is a date specified, then it is used.  URLs would look like:</p>
  
  <pre><code>localhost:3000/journals/7/
  localhost:3000/journals/7/2013-01-22/
  </code></pre>
  
  <p>The first would show Today's contents.  The second would show contents from the Jan 22.</p>
  
  <p>I started with this route:</p>
  
  <pre><code>match '/journals/:id(/:date)', to: 'journals#show'
  </code></pre>
  
  <p>And a corresponding Controller</p>
  
  <pre><code>class JournalsController &lt; ApplicationController
    def show
        @user = User.find(params[:id])
        if params[:date]
          @date = Date.parse(params[:date])
        else 
          @date = Date.today
        end
    end  
  end
  </code></pre>
  
  <p>And this works fine, but how can I generate URLs using the url helpers?  I tried this:</p>
  
  <pre><code>&lt;%= link_to "&lt; Yesterday", journal_path(id: @user, date: @date.yesterday) %&gt;
  </code></pre>
  
  <p>Which seems to actually work fine, but it gives me a url like this:</p>
  
  <pre><code>localhost:3000/journals/7?date=2013-01-22
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>localhost:3000/journals/7/2013-01-22
  </code></pre>
  
  <p>How can I keep the URLs consistently built like  /journals/:id/:date</p>
  
  <p>If there is a better approach please let me know. </p>