通常我有MenuItems模型,并尝试使’/ menu_items(/:id(:/ some_action))’的URL看起来像’/ menu(/:id(:/ some_action))’
在Rails 2.3.5它是
map.resources:menu_items,as as => :菜单,:path_names => {:new => ‘add’}
现在在Rails 3.0.3中,我可以使用这段巨大的代码段来处理它
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
但是由于代码量庞大,因此看起来不正确.
好像就像第二个Rails的map.some_name一样.
任何帮助/建议/指南? (谢谢)
解决方法
http://guides.rubyonrails.org/routing.html#customizing-resourceful-routes
resources :menu,:controller => "menu_items",:path_names => { :new => "add" }
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"}