假设我有以下条件适用于大量资源:
:only => [:create, :destroy], :defaults => {:format => :json}, :constraints => {:format => :json}
我的问题是如何将这些条件同时应用于多条路线,例如:
group resources [:resource1, :resource2] do
:only => [:create, :destroy], :defaults => {:format => :json}, :constraints => {:format => :json}
end
答案 0 :(得分:1)
routes.rb
只是红宝石,所以你可以把红宝石代码放在这个顶部
my_defaults = {
only: [:create, :destroy],
defaults: { format: :json },
constraints: { format: :json }
}
Rails.application.routes.draw do
# ...
resources :users, my_defaults
# ...
end