Route.rb problems - help

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
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.

Any help on this please!

Hi Don,

On Jan 11, 2008 10:03 AM, dhf [email protected] 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.