Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
Created October 29, 2010 13:21
Show Gist options
  • Save pixeltrix/653543 to your computer and use it in GitHub Desktop.
Save pixeltrix/653543 to your computer and use it in GitHub Desktop.

Revisions

  1. pixeltrix created this gist Oct 29, 2010.
    35 changes: 35 additions & 0 deletions routes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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