# Issue with Routes

**URL:** <https://www.ruby-forum.com/t/issue-with-routes/150256>\
**Category:** Rails\
**Created:** [October 6, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/issue-with-routes/150256 "2008-10-06T17:32:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Memo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a5b964/32.png) [@Memo](https://www.ruby-forum.com/u/Memo)\
**Post date:** [October 6, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/issue-with-routes/150256/1 "2008-10-06T17:32:34Z")

</div>

I want a form on my home page to be handled by a different controller  
(buy\_controller) but I’m having issues. The code works fine when I  
have the form under the “buy” views

I’m pretty new to Rails. I’ve tried different ways of doing this but  
I can’t seem to figure it out. The latest error is doesn’t let me  
load the home page.

Error

* * *

ActionController::RoutingError in Home#index

Showing home/index.rhtml where line #42 raised:

buy\_url failed to generate from  
{:controller=\>“buy”, :action=\>“search\_for\_product”}, expected:  
{:controller=\>“buy”, :action=\>“show”}, diff: {:action=\>“show”}

Extracted source (around line #42):

39:

  
40: 
# \<%= “Product Search”.t %\>
  
41: 
  
42: \<% form\_for :buy, :url =\> buy\_path(:action =\>  
‘search\_for\_product’), :html =\> { :id =\> ‘search\_form’ } do |form| %\>  
43: \<%= form.text\_field :query, :size =\> 70 -%\>  
44: \<%= submit\_tag “Search”.t %\>  
45: ![loading](https://test.ruby-forum.com/images/%0Alive_tree_loading_spinner.gif)

Here is my code:

routes.rb

* * *

map.resources :buy

/home/index.rhtml

* * *

\<% form\_for :buy, :url =\> buy\_path(:action =\>  
‘search\_for\_product’), :html =\> { :id =\> ‘search\_form’ } do |form| %\>  
\<%= form.text\_field :query, :size =\> 70 -%\>  
\<%= submit\_tag “Search” %\>  
\<% end %\>

buy\_controller

* * *

def search\_for\_product  
if params[:buy][:query].blank?  
…  
end  
if @fail  
flash[:error] = @err\_msg  
redirect\_to :back  
else  
respond\_to do |format|  
format.html { render :template =\> ‘buy/search’,  
:layout =\> ‘buy’ } # search.rhtm  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![Memo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a5b964/32.png) [@Memo](https://www.ruby-forum.com/u/Memo)\
**Post date:** [October 6, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/issue-with-routes/150256/2 "2008-10-06T19:05:00Z")

</div>

I finally figured out the problem.

I added a named route  
map.buy\_search ‘/buy/search\_for\_product’, :controller =\>  
“buy”, :action =\> ‘search\_for\_product’

and changed /home/index.rhtml

* * *

\<% form\_for :buy, :url =\> buy\_search\_path, :html =\> { :id =\>  
‘search\_form’ } do |form| %\>  
\<%= form.text\_field :query, :size =\> 70 -%\>  
\<%= submit\_tag “Search” %\>  
\<% end %\>

I really recommend using Railscasts ([http://railscasts.com](http://railscasts.com)) by Ryan  
Bates for anyone else that’s new to Rails.
