结合类似的资源路线?

时间:2014-01-06 18:49:05

标签: ruby-on-rails ruby-on-rails-4 routes

我的Rails 4应用程序中有以下一组收集路径:

resources :stats do
  collection do
    match 'mrr', via: [:get, :post]
    match 'upgrades', via: [:get, :post]
    match 'arpu', via: [:get, :post]
    match 'arr', via: [:get, :post]
    match 'ltv', via: [:get, :post]
  end
end

至少还有十几个match行。

有没有办法压缩,所以我不再重复(特别是via方法选项)?

1 个答案:

答案 0 :(得分:5)

它完全可读,但你可以这样做:

resources :stats do
  collection do
    %w(mrr upgrades arpu arr ltv).each do |stat| 
      match stat, via: [:get, :post]
    end
  end
end
相关问题