Refactoring routes - serving different layouts
Posted
by dmclark
on Stack Overflow
See other posts from Stack Overflow
or by dmclark
Published on 2010-02-01T14:56:21Z
Indexed on
2010/04/17
8:03 UTC
Read the original article
Hit count: 236
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
© Stack Overflow or respective owner