pcasa
pcasa

Reputation: 3730

Ruby Name Routes with permalinks and static pages

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 :products
  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

Upvotes: 0

Views: 147

Answers (1)

jshen
jshen

Reputation: 11907

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'

Upvotes: 1

Related Questions