Skip to content

Instantly share code, notes, and snippets.

@nelson-o
Forked from pixeltrix/routes.rb
Created May 30, 2014 04:37
Show Gist options
  • Select an option

  • Save nelson-o/acf43b6c7407f586c7ed to your computer and use it in GitHub Desktop.

Select an option

Save nelson-o/acf43b6c7407f586c7ed to your computer and use it in GitHub Desktop.

Revisions

  1. @pixeltrix 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