title: Using named routes with parameters and form_tag
body: <p>I'm trying to create a simple search form in Rails, but I think I'm missing something.</p>
  
  <p>I have a named route for search:</p>
  
  <pre><code>map.search ":first_name/:last_name", :controller =&gt; "home", :action =&gt; "search"
  </code></pre>
  
  <p>I'm trying to use that in my search form:</p>
  
  <pre><code>&lt;% form_tag(search_path, :method =&gt; 'get') do %&gt;
    &lt;%= text_field_tag(:first_name) %&gt;
    &lt;%= text_field_tag(:last_name) %&gt;
    &lt;%= submit_tag("Search") %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But when I load up the search form I get an ActionController::RoutingError:</p>
  
  <blockquote>
    <p>search_url failed to generate from {:action=>"search", :controller=>"home"} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: [:first_name, :last_name] - are they all satisfied?</p>
  </blockquote>
  
  <p>What am I missing? I thought the fields defined in my form would be automatically linked up with my route parameters. :-/</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I understand that search_path is generated before the form is displayed now, so it can't be updated. Obvious in hindsight!</p>
  
  <p>I changed my routes:</p>
  
  <pre><code>map.search 'search', :controller =&gt; "home", :action =&gt; "search"
  map.name ':first_name/:last_name', :controller =&gt; "home", :action =&gt; "name"
  </code></pre>
  
  <p>And now the <code>search</code> action just does:</p>
  
  <pre><code>def search
    redirect_to name_path(params)
  end
  </code></pre>
  
  <p>It all works a treat! The main goal here was getting that URL from the <em>name</em> named route as result of doing a search. Thanks guys!</p>