map.resources and custom nested routes
I encountered an error in rails trying to create a nested route in rails 2.x
map.import_time_cards 'users/:user_id/time_cards/import', :controller => 'time_cards', :action => 'import'
Wasn't setting up a route for users because this route was being setup automatically and overwritten by:
map.resources :users, :has_many => [:notes, :addresses, :expenses, :time_cards] , :collection => [:login, :logout, :disable, :enable]
So after digging around on the rails api I discovered that map.resources takes a block so my solution to this problem was :
map.resources(:users, :has_many => [:notes, :addresses, :expenses] , :collection => [:login, :logout, :disable, :enable]) do |user| user.resources :time_cards, :collection => [:import] end
By using a block this tells rails to include route to 'users/1/time_cards/import' instead of appending import as the id for the show route.