加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails 3 |路由:现在如何重命名资源标题?

发布时间:2020-12-16 20:02:08 所属栏目:百科 来源:网络整理
导读:通常我有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中,我可以使
通常我有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"}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读