Refactoring routes - serving different layouts
- by dmclark
As a Rails NOOB, I started with a routes.rb of:
ActionController::Routing::Routes.draw do |map|
map.resources :events
map.connect 'affiliates/list', :controller => "affiliates", :action => "list"
map.connect 'affiliates/regenerate_thumb/:id', :controller => "affiliates", :action => "regenerate_thumb"
map.connect 'affiliates/state/:id.:format', :controller => "affiliates", :action => "find_by_state"
map.connect 'affiliates/getfeed', :controller => "affiliates", :action => "feed"
map.resources :affiliates, :has_many => :events
map.connect ":controller/:action"
map.connect '', :controller => "affiliates"
map.connect ":controller/:action/:id"
map.connect ":controller/:action/:id/:format"
end
and i'm trying to tighten it up. and I've gotten as far as:
ActionController::Routing::Routes.draw do |map|
map.resources :events, :only => "index"
map.resources :affiliates do |affiliates|
affiliates.resources :has_many => :events
affiliates.resources :collection => { :list => :get, :regenerate_thumb => "regenerate_thumb" }
end
# map.connect 'affiliates/regenerate_thumb/:id', :controller => "affiliates", :action => "regenerate_thumb"
map.connect 'affiliates/state/:id.:format', :controller => "affiliates", :action => "find_by_state"
map.connect 'affiliates/getfeed', :controller => "affiliates", :action => "feed"
map.root :affiliates
end
what is confusing to me is routes vs parameters.. For example, I realized that the only difference between list and index is HOW it is rendered, rather than WHAT is rendered.
Having a different action (as I do now) feels wrong but I can't figure out he right way.
Thanks