Generally I have MenuItems model and trying to make '/menu_items(/:id(:/some_action))' URLs looks like '/menu(/:id(:/some_action))'
In Rails 2.3.5 it was
map.resources :menu_items, :as => :menu, :path_names => { :new => 'add' }
Now in Rails 3.0.3 I'm able to handle it using this huge paragraph of code
resources :menu_items, :path_names => { :new => 'add' }
match 'menu/' => 'menu_items#index', :as => :menu
match 'menu/add' => 'menu_items#new', :as => :new_menu
match 'menu/:id' => 'menu_items#show', :as => :show_menu
match 'menu/:id/edit' => 'menu_items#edit', :as => :edit_menu
But it looks incorrect because of huge amount of code. Seems :as works like 2nd Rails' map.some_name now.
Any help/suggestions/guides? (Thanks)
http://guides.rubyonrails.org/routing.html#customizing-resourceful-routes
resources :menu, :controller => "menu_items", :path_names => { :new => "add" }
Output is quite close to what you're after:
menu_index GET /menu(.:format) {:controller=>"menu_items", :action=>"index"}
POST /menu(.:format) {:controller=>"menu_items", :action=>"create"}
new_menu GET /menu/add(.:format) {:controller=>"menu_items", :action=>"new"}
edit_menu GET /menu/:id/edit(.:format) {:controller=>"menu_items", :action=>"edit"}
menu GET /menu/:id(.:format) {:controller=>"menu_items", :action=>"show"}
PUT /menu/:id(.:format) {:controller=>"menu_items", :action=>"update"}
DELETE /menu/:id(.:format) {:controller=>"menu_items", :action=>"destroy"}
Another way
resources :menu, :as => :menu_items, :controller => :menu_items
This approach has the advantage that the exiting helper methods such as menu_items_path still work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With