andi/simple-navigation — Issue #84: Highlighting on sub_path not working for namespaced routes
Author: Kezzer
Created: 2012-01-28 21:36:28+00:00
State: open

Basically I've got a namespace called admin and when viewing an entity the generated URLs are incorrect. They use the ID of the viewed entity as part of the path, which is wrong. Here's some code to chew on in my routes:

namespace :admin do
resources :bookings, :staff, :pages, :treatments, :clients, :reports, :vouchers

match 'bookings/cancel/:id' => 'bookings#cancel', :as => :cancel_booking
match 'treatments/cost/:id' => 'treatments#cost', :as => :treatment_cost, :via => :get
end

Then the navigation.rb file:

primary.item :bookings, 'Bookings', admin_bookings_path, :highlights_on => :subpath
primary.item :treatments, 'Treatments', admin_treatments_path, :highlights_on => :subpath
primary.item :clients, 'Clients', admin_client_path, :highlights_on => :subpath
primary.item :vouchers, 'Vouchers', admin_voucher_path, :highlights_on => :subpath
primary.item :reports, 'Reports', admin_report_path, :highlights_on => :subpath
primary.item :pages, 'Pages', admin_pages_path, :highlights_on => :subpath
primary.item :staff, 'Staff', admin_staff_path, :highlights_on => :subpath

If, for example, I'm viewing the following: http://localhost:3000/admin/clients/2 then the following URL's are generated for each of the links:

http://localhost:3000/admin/bookings
http://localhost:3000/admin/treatments
http://localhost:3000/admin/clients/2
http://localhost:3000/admin/vouchers/2
http://localhost:3000/admin/reports/2
http://localhost:3000/admin/pages
http://localhost:3000/admin/staff/2

Any with /2 on the end are wrong (obviously).

Any idea what the heck is going on here?