Custom Rails actions: I have issues every time
- by normalocity
Every time I go to add a custom action to a controller, I completely screw it up somehow.
I'm trying to add a route "listings/buyer_listings", that will display all of my listings where someone is a buyer (rather than a seller).
With the routes.rb file below, when I go to "listings/buyer_listings", I get routed instead to "users"
WTF? In the past, I've had to define my routes using "map.", but this seems like a very verbose way to do something that should work with the :collection specification. You can see that I've done this with many routes as specified toward the end of the file, such as "edit_my_profile", etc.
If I put the ":collection" part last my browser routes to the "show" action, which is not the correct action, and which also doesn't make sense to me why it would even do this. If I do "rake routes", my routes look correctly mapped. If I go into a Ruby console and have it recognize the url, it maps to the correct action, so what am I missing?
ActionController::Routing::Routes.draw do |map|
map.resources :locations
map.resources :browse_boxes
map.resources :tags
map.resources :ratings
map.resources :listings, :collection => { :buyer_listings => :get }, :has_many => :bids, :has_many => :comments
map.resources :users
map.resources :invite_requests
map.resource :user_session
map.resource :account, :controller => "users"
map.root :controller => "listings", :action => "index" # optional, this just sets the root route
map.login "login", :controller => "user_sessions", :action => "new"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
map.search "search", :controller => "listings", :action => "search"
map.edit_my_profile "edit_my_profile", :controller => "users", :action => "edit_my_profile"
map.all_listings "all_listings", :controller => "listings", :action => "all_listings"
map.my_listings "my_listings", :controller => "listings", :action => "my_listings"
map.posting_guidelines "posting_guidelines", :controller => "listings", :action => "posting_guidelines"
map.filter_on "filter_on", :controller => "listings", :action => "filter_on"
map.top_25_tags "top_25_tags", :controller => "tagging_search", :action => "top_25_tags"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end