tonypm
2008-Feb-20 11:39 UTC
help with routing - prefix added automatically?? - lookup action wanted
I want to add a lookup action to my controller. I am trying to stay in the REST framework, so I have used map.resources :products I tried adding :member=>{:lookup=>:get} but this created a route that expected an id. so I did this: map.connect ''product/ lookup'', :controller=>''products'', :action=>''lookup'' map.resources :products This works but am I doing the right thing, because now I cannot use lookup_products_path SO, instead I used ''products/lookup'' as a url string. This is a link which is in a main menu in the layout, and works if I am not already serving an action from the products controller. BUT, if I click on the link whilst I am already in a products view, the url returned is: products/products/lookup - and is obviously not found NOW, I discovered that if I put the leading / in the url ''/products/ lookup'' then all is fine. QUESTION: what is rails doing to the incoming request that causes the prefix to be automatically added. If it is intended, then it is a feature that I am sure could work to my advantage when trying to use namespaces (I have failed in this endeavour so far). Please could someone help me, I really find the routing stuff hard to grasp. Is there any helpful documentation, I have the Agile rails book, the RESTful rails pdf and the peepcode rails 2 pdf, but I still cannot completely grasp it (I know I am being slow), but I do keep trying - lol. Thanks Tony --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten
2008-Feb-20 12:46 UTC
Re: help with routing - prefix added automatically?? - lookup action wanted
If you want a custom REST action that doesn''t require an ID, use :collection instead of :member: map.resources :products, :collection => { :lookup => :get } On 20 Feb., 12:39, tonypm <tonypmar...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> I want to add a lookup action to my controller. > > I am trying to stay in the REST framework, so I have used > > map.resources :products > > I tried adding :member=>{:lookup=>:get} > > but this created a route that expected an id. > > so I did this: > > map.connect ''product/ > lookup'', :controller=>''products'', :action=>''lookup'' > map.resources :products > > This works but am I doing the right thing, because now I cannot use > lookup_products_path > SO, instead I used ''products/lookup'' as a url string. > > This is a link which is in a main menu in the layout, and works if I > am not already serving an action from the products controller. > > BUT, if I click on the link whilst I am already in a products view, > the url returned is: > products/products/lookup - and is obviously not found > > NOW, I discovered that if I put the leading / in the url ''/products/ > lookup'' then all is fine. > > QUESTION: what is rails doing to the incoming request that causes the > prefix to be automatically added. If it is intended, then it is a > feature that I am sure could work to my advantage when trying to use > namespaces (I have failed in this endeavour so far). > > Please could someone help me, I really find the routing stuff hard to > grasp. Is there any helpful documentation, I have the Agile rails > book, the RESTful rails pdf and the peepcode rails 2 pdf, but I still > cannot completely grasp it (I know I am being slow), but I do keep > trying - lol. > > Thanks > Tony--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tonypm
2008-Feb-21 20:43 UTC
Re: help with routing - prefix added automatically?? - lookup action wanted
On Feb 20, 12:46 pm, Thorsten <duple...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> If you want a custom REST action that doesn''t require an ID, > use :collection instead of :member: > > map.resources :products, :collection => { :lookup => :get } >Thanks Thorsten - that worked. I had missed :collection. I am still curious why rails automatically adds the prefix products to the url if the referrer was the products controller and I used the string url ''products/lookup''? Tonypm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten
2008-Feb-25 10:12 UTC
Re: help with routing - prefix added automatically?? - lookup action wanted
i guess that''s not rails, that''s your browser. if you omit the leading "/", it''s a relative path, so if the browser displays a page under www.expample.com/products, and on this page is a link to "products/lookup", it means for the browser: "/products/ products/lookup", as this path is relative to the current "directory" (= URL). Adding a leading slash makes it absolute to the base domain. Rails link helpers take care of this automagically behind the scenes, but when your create links with hardcoded strings, you have to watch out for that. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---