Skip to content

Instantly share code, notes, and snippets.

@citrus
Created May 3, 2011 18:08
Show Gist options
  • Save citrus/953865 to your computer and use it in GitHub Desktop.
Save citrus/953865 to your computer and use it in GitHub Desktop.
wtf routes
# routes.rb
Rails.application.routes.draw do
scope(:module => "News") do
constraints(
:year => /\d{4}/,
:month => /\d{1,2}/,
:day => /\d{1,2}/
) do
get '/news/:year(/:month)(/:day)' => 'articles#index', :as => :article_date
get '/news/:year/:month/:day/:id' => 'articles#show', :as => :full_article
end
get '/news/search/:query', :to => 'articles#search', :as => :search_articles, :query => /.*/
resources :articles, :path => 'news' do
get :archive, :on => :collection
end
end
namespace :admin do
scope(:module => "News") do
resources :articles do
resources :images, :controller => "article_images" do
collection do
post :update_positions
end
end
resources :products, :controller => "article_products"
end
end
end
end
# in my view
<% tag_cloud @tags, %w(neat cool rad awesome) do |tag, css_class| %>
<li><%= link_to tag.name, search_articles_path(tag.name), :class => css_class %></li>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment