Skip to content

Instantly share code, notes, and snippets.

@markauskas
Forked from pixeltrix/routes.rb
Created November 20, 2010 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markauskas/708071 to your computer and use it in GitHub Desktop.
Save markauskas/708071 to your computer and use it in GitHub Desktop.
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
:defaults => {
:page => 1,
:extension => 'html',
:locale => 'en'
}
# products_path(:page => 1)
# => /products.html
# products_path(:page => 2)
# => /products/page/2.html
# products_path(:page => 2, :locale => 'de')
# => /de/products/page/2.html
# products_path('computers', :page => 2, :locale => 'de')
# => /de/products/computers/page/2.html
# products_path('computers/apple', :page => 2, :locale => 'de')
# => /de/products/computers/apple/page/2.html
# products_path('computers/apple')
# => /products/computers/apple.html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment