title: Rails routing -- how to route to item with random id number
body: <p>I have a very simple rails app. I generated scaffolding for Card which among other things allows me to go to a specific route for record with id <a href="http://app.com/cards/3" rel="nofollow">http://app.com/cards/3</a>.</p>
  
  <p>When I go to root <a href="http://app.com" rel="nofollow">http://app.com</a> I want to be routed to show a random card with random id, say "X" (<a href="http://app.com/cards/X" rel="nofollow">http://app.com/cards/X</a>)</p>
  
  <p>I'm pretty sure this is wrong, but I attempted to add the following in the Cards Controller:</p>
  
  <pre><code>def random
    @card = Card.order("RANDOM()").first
  end
  </code></pre>
  
  <p>And then add in routes.rb:</p>
  
  <pre><code>root :to =&gt; 'cards#random'
  </code></pre>
  
  <p>The error I get in browser when I try to go to route:</p>
  
  <pre><code>Template is missing
  
  Missing template cards/random, application/random with {:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :coffee]}. Searched in: * "/Users/patricia/Documents/Repos/coastguard-quiz-rails/app/views"
  </code></pre>
  
  <p>And finally when I run "rake routes" I get:</p>
  
  <pre><code>    cards GET    /cards(.:format)          cards#index
            POST   /cards(.:format)          cards#create
   new_card GET    /cards/new(.:format)      cards#new
  edit_card GET    /cards/:id/edit(.:format) cards#edit
       card GET    /cards/:id(.:format)      cards#show
            PUT    /cards/:id(.:format)      cards#update
            DELETE /cards/:id(.:format)      cards#destroy
       root        /                         cards#random
  </code></pre>
  
  <p>Could someone please guide me in the right direction? Thanks in adv.</p>