ruby-on-rails – 使用Rails 3路由添加自定义:新路由
发布时间:2020-12-16 22:57:00 所属栏目:百科 来源:网络整理
导读:在Rails 2中,我们可以为资源丰富的路由添加自定义新操作,例如: map.resources :users,:new = {:apply = :get} 我们如何在Rails 3中实现同样的功能? resources :users do get :apply,:on = :new # does not work new do get :apply # also does not work en
在Rails 2中,我们可以为资源丰富的路由添加自定义新操作,例如:
map.resources :users,:new => {:apply => :get} 我们如何在Rails 3中实现同样的功能? resources :users do get :apply,:on => :new # does not work new do get :apply # also does not work end end 有任何想法吗? 解决方法
您可以在边缘路由指南中使用:path_names作为
explained:
resources :users,:path_names => { :new => "apply" } 这只会改变应用的路径,它仍将被路由到新的动作.我认为不再明确支持改变(这可能是一件好事). 如果你想保留你的申请行动,你应该做: resources :users,:except => :new do collection do get :apply end end 但它让您想知道将apply操作重命名为new是否更好. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |