开发者

Ruby Name Routes with permalinks and static pages

开发者 https://www.devze.com 2022-12-19 20:43 出处:网络
I have several static pages and a couple of dynamic pages.Static pages are under the \"Info\" controller.Dynamic pages are under \"products\".I want to access \"products\" from their :permalinkI can o

I have several static pages and a couple of dynamic pages. Static pages are under the "Info" controller. Dynamic pages are under "products". I want to access "products" from their :permalink I can only get map.info or map.products to work but not both.

 ActionController::Routing::Routes.draw do |map|
  map.resources :pr开发者_如何学编程oducts
  map.resources :info
  map.root :controller => "products"
  map.info ':action', :controller => "info"
  map.products ':permalink', :controller => 'products', :action => 'show'
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
 end


Let's say you go to http://yoursite.com/something

How can the routes determine if it's a product or info page? It can't, and that's why it won't work. You have to put one of them under a namespace of some sort.

map.info ':action', :controller => "info"
map.products '/products/:permalink', :controller => 'products', :action => 'show'
0

精彩评论

暂无评论...
验证码 换一张
取 消