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