# Route.rb problems - help

**URL:** <https://www.ruby-forum.com/t/route-rb-problems-help/125655>\
**Category:** Rails\
**Created:** [January 11, 2008, 12:04am UTC](https://www.ruby-forum.com/t/route-rb-problems-help/125655 "2008-01-11T00:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 11, 2008, 12:04am UTC](https://www.ruby-forum.com/t/route-rb-problems-help/125655/1 "2008-01-11T00:04:39Z")

</div>

I am trying to create an application thats allows searching on an item  
number. There are multiple items in the DB with the same number  
(different vendors).

My index page has a simple form that just accepts an item number in a  
form as:  
\<% form\_tag(all\_item\_search\_path) do %\>

When I try to load this page, I get:  
all\_item\_search\_url failed to generate from  
{:method=\>:get, :action=\>“search”, :controller=\>“public”} - you may  
have ambiguous routes, or you may need to supply additional parameters  
for this route. content\_url has the following required parameters:  
[“search”, :item\_number] - are they all satisfied?

My route.rb contains:  
map.all\_item\_search “/search/:item\_number”, :controller =\>  
“public”, :action =\> “search”, :method =\> :get

and rake routes gives me the following:  
all\_item\_search /search/:item\_number  
{:method=\>:get, :action=\>“search”, :controller=\>“public”}

I can enter a url in the browser as such:  
[http://localhost:3000/search/1234](http://localhost:3000/search/1234)  
I get the results of the search back.

Also, would it be better to use /search?item=1234 # item numbers are  
alphanumeric and can have special characters

The last part of the question is how will an xml request be specified.  
I know they are specified as /items.1.xml in a normal case.

Thank you  
Don F.

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 11, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/route-rb-problems-help/125655/2 "2008-01-11T20:47:17Z")

</div>

Any help on this please!

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 12, 2008, 5:02am UTC](https://www.ruby-forum.com/t/route-rb-problems-help/125655/3 "2008-01-12T05:02:11Z")

</div>

Hi Don,

On Jan 11, 2008 10:03 AM, dhf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> all\_item\_search\_url failed to generate from  
> {:method=\>:get, :action=\>“search”, :controller=\>“public”} - you may  
> have ambiguous routes, or you may need to supply additional parameters  
> for this route. content\_url has the following required parameters:  
> [“search”, :item\_number] - are they all satisfied?

As the error suggests, you need an item\_number parameter:

form\_tag all\_item\_search\_path(item\_number) do  
…  
end

> Also, would it be better to use /search?item=1234 # item numbers are  
> alphanumeric and can have special characters

Remove :item\_number from the route:

map.all\_item\_search “/search”,  
:controller =\> “public”, :action =\> “search”, :method =\> :get

And now:

form\_tag all\_item\_search\_path(:item\_number =\> item\_number) do  
…  
end

> The last part of the question is how will an xml request be specified.  
> I know they are specified as /items.1.xml in a normal case.

Add a formatted route:

map.formatted\_all\_item\_search “/items.:format”,  
:controller =\> “public”, :action =\> “search”, :method =\> :get

form\_tag formatted\_all\_item\_search\_path(‘xml’, :item\_number =\>  
item\_number) do  
…  
end

Having said all this, I’m wondering if a more RESTful architecture  
would be a better way to go–when you do things RESTfully, you get all  
this stuff for free. It sounds like you have a few resources like  
searches and items, but as I lack the bigger picture, that’s as far as  
I can really go here.

Hope this helps anyway.

Regards,  
George.
