Rails double nested routes, broken up -


i have these routes:

  map.resources :categories |category|     category.resources :sub_categories   end    map.resources :sub_categories |sub_category|     sub_category.resources :events   end 

this url doesnt have doubly nested, want keep url max of 2 objects deep.

the problem events, i want require there /sub_categories/:sub_category_id path_prefix, using

  map.resources :events, path_prefix => '/sub_categories/:sub_category_id' 

gives me routes

  event_path 

what want have is

  sub_category_event_path 

because time user wants *sub_category*, want url require *category_id* provided, if user wants see event, sub_category_id must provided.

you're right, generate event_path, event_path require :sub_category_id option. sub_category_event_path helper, write one:

class applicationcontroller < actioncontroller::base   private   def sub_category_event_path(sub_category, event)      event_path(event, :sub_category_id => sub_category)   end   helper_method :sub_category_event_path end 

unfortunately, if ever want sub_category_event_url, you'll have write 1 too.

rails 3 have new support shallow routes might interest you. consider upgrading!


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -