Let say I have following conditions to apply on a bunch of resources:
:only => [:create, :destroy], :defaults => {:format => :json}, :constraints => {:format => :json}
My question is how can I apply these conditions to multiple routes at once, e.g:
group resources [:resource1, :resource2] do
:only => [:create, :destroy], :defaults => {:format => :json}, :constraints => {:format => :json}
end
routes.rb
is just ruby, so you can place ruby code on top like this
my_defaults = {
only: [:create, :destroy],
defaults: { format: :json },
constraints: { format: :json }
}
Rails.application.routes.draw do
# ...
resources :users, my_defaults
# ...
end