在 Rails 2 中,我们可以添加自定义 new
对资源丰富的路线采取的行动,例如:
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" }
那只会将路径更改为
apply
,它仍然会被路由到 new
行动。我认为不再明确支持更改(这可能是一件好事)。如果您想保留您的
apply
行动,你可能应该这样做:resources :users, :except => :new do
collection do
get :apply
end
end
但它让您想知道重命名
apply
是否更好。行动到 new
.
关于ruby-on-rails - 添加自定义 :new routes using Rails 3 routing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3044531/