title: Routing and form in Rails
body: <p>I have a controller for a resource, BuddiesController. My routes config file up until now has been </p>
  
  <pre><code>resources :buddies
  match ':controller(/:action(/:id))', :via =&gt; [:get, :post]
  </code></pre>
  
  <p>I didn't realize what the ' resources :buddies ' line was doing until I read up on routing in Rails just now, because the behavior has been identical with what I expected until now. The problem was that I wanted to add a non-CRUD action to the controller: 'search'. Every time I used link_to(:action => 'search'), I would get an exception saying that action 'show' could not be found despite the url being ' localhost:3000/buddies/search ' as expected. I have several questions arising from this:</p>
  
  <p>Firstly, the form I used in 'new' stopped working:</p>
  
  <pre><code>%= form_for(@buddy, {:action =&gt; :create, :method =&gt; :post, :html =&gt; {:role =&gt; "form"}}) do |f| %&gt;
  </code></pre>
  
  <p>because buddies_path couldn't be found. How could I manually add a buddies_path to my routes?</p>
  
  <p>Secondly, I revised the form to use:</p>
  
  <pre><code>&lt;%= form_for(@buddy, :url =&gt; {:action =&gt; :create, :id =&gt; @buddy.id}, :html =&gt; {:role =&gt; "form", :id =&gt; @buddy.id}) do |f| %&gt;
  </code></pre>
  
  <p>but this has caused the form to give me password and email confirmation not matching errors even if they match. What's going on here?</p>
  
  <p>Lastly, what is the best way to add a search action to my resource?</p>