Rails 3,为每种资源创建一条新路线 [英] Rails 3, create a new route for every resource
本文介绍了Rails 3,为每种资源创建一条新路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我正在研究的项目中,我想为多个资源添加相同的路线。我知道我可以做到
In a project I'm working on I'd like to add the same route for multiple resources. I know I can do this
resources :one do
collection do
post 'common_action'
end
end
resources :two do
collection do
post 'common_action'
end
end
我至少有10个不同的资源,它们都需要相同的路由,因为每个控制器将执行相同的操作。
I have at least 10 different resources which all need the same route, as each controller will have the same action. Is there a way to define this less repetitively?
推荐答案
%w(one two three four etc).each do |r|
resources r do
collection do
post 'common_action'
end
end
end
这篇关于Rails 3,为每种资源创建一条新路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文