Hello,
please, explain me how to write a rails routing:
I want to route all requiests, what income to a controller, to requested
action, and all other - to certain controller/action
e.g.:
map.connect(‘products2/:action’, :controller => “products2”)
map.connect(’:controller/:action/:id’, :controller => “products2”,
:action => ‘error’)
when user requests SERVER/products2/test1 he gets a right result, but in
other case (e.g., SERVER/prod/1) I get “Routing Error” message instead
of redirecting to products/error.
Please, advise me how to resolve it ?
Thanks.
Dunno, but my guess is that it’s matching :controller in your last
pattern and going with that. The specifics of the routing error would
give more info. In the absence of that, as a suggestion, maybe
something for your default like
map.connect(’:any/:other:/:thing, :controller => ‘products2’, :action
=> ‘error’, :requirements => { :any => /./, :other => /./, :thing
=> /.*/ })
…
…
John B.
From Agile Web D. book:
Catch-all so we can gracefully handle badly-formed requests
map.connect “*anything”, :controller => “blog”, :action =>
“unknown_request”
Notice how we put the catchall rule ("*anything") at the end
of the list. Because this rule matches any request, putting it earlier
would
stop subsequent rules from being examined.
Lee пиÑ?еÑ?:
I am reading this book, but I missed it
I thank you for the answer.