[英]Rails route for mapping records by name rather than id?
In my Rails application, I would like to route /product/productname1, /product/productname2, etc. to ProductController::index(). 在我的Rails应用程序中,我想将/ product / productname1,/ product / productname2等路由到ProductController :: index()。 I don't want separate methods in my ProductController for each product name route.
我不想在ProductController中为每个产品名称路由使用单独的方法。
What would my route look like? 我的路线是什么样的?
I have 我有
map.connect 'products/:name', :controller => 'products', :action => 'index'
But when I go to 但是当我去
/products/something
I get 我懂了
No action responded to show. Actions: index
Does it have to do with the ordering of your routes file? 与路由文件的顺序有关吗? eg is this coming after map.resources :products?
例如,这是在map.resources:products之后吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.