title: How to write a dynamic route in Rails 3?
body: <p>I'm trying to write a generic route that will allow me to refer to it by the controller's action.</p>
  
  <p>I'm using the following line:</p>
  
  <pre><code>  match ':action' =&gt; 'pages#:action', :as =&gt; 'action'
  </code></pre>
  
  <p>let's say an action named `foobar' in the pages controller. I'd like to be able to write</p>
  
  <pre><code>link_to 'Click Me', pages_foobar_path
  </code></pre>
  
  <p>in a view. The problem is that I get the error <code>Invalid route name: ':action'</code> when I try to write that route.</p>
  
  <p>Mind you, the line</p>
  
  <pre><code>match ':action' =&gt; 'pages#:action'
  </code></pre>
  
  <p>without the <code>:as</code> parameter works perfectly, but then I have to manually write the path, as such:</p>
  
  <pre><code>link_to 'Click Me', '/pages/foobar'
  </code></pre>
  
  <p>any way around that?</p>