Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default format for routing in Rails?

There is the following code for routing:

  resources :orders, only: [:create], defaults: { format: 'json' }
  resources :users,  only: [:create, :update], defaults: { format: 'json' } 
  resources :delivery_types, only: [:index], defaults: { format: 'json' }
  resources :time_corrections, only: [:index], defaults: { format: 'json' }

It is possible to set default format for all resources using 1 string without 'defaults' hash on each line? Thanks.

like image 807
malcoauri Avatar asked Jan 09 '14 10:01

malcoauri


1 Answers

Try something like this:

scope format: true, defaults: { format: 'json' } do
  resources :orders, only: [:create]
  resources :users,  only: [:create, :update] 
  resources :delivery_types, only: [:index]
  resources :time_corrections, only: [:index]
end
like image 199
siekfried Avatar answered Sep 21 '22 15:09

siekfried