Route.rb problems - help

25 views
Skip to first unread message

dhf

unread,
Jan 10, 2008, 6:03:42 PM1/10/08
to Ruby on Rails: Talk
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 French

dhf

unread,
Jan 11, 2008, 2:46:51 PM1/11/08
to Ruby on Rails: Talk
Any help on this please!

George

unread,
Jan 11, 2008, 11:01:01 PM1/11/08
to rubyonra...@googlegroups.com
Hi Don,

On Jan 11, 2008 10:03 AM, dhf <dhf...@gmail.com> wrote:
>
> 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?

As the error suggests, you need an item_number parameter:

form_tag all_item_search_path(item_number) do
...
end

> 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

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.

Reply all
Reply to author
Forward
0 new messages