结合类似的资源路线?

Shp*_*ord 0 routes ruby-on-rails ruby-on-rails-4

我在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
Run Code Online (Sandbox Code Playgroud)

至少还有十几个这样的match线.

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

apn*_*ing 5

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

resources :stats do
  collection do
    %w(mrr upgrades arpu arr ltv).each do |stat| 
      match stat, via: [:get, :post]
    end
  end
end
Run Code Online (Sandbox Code Playgroud)