如何在Rails中设置路由的默认格式?

mal*_*uri 5 ruby ruby-on-rails rails-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' }
Run Code Online (Sandbox Code Playgroud)

可以使用1个字符串为所有资源设置默认格式,每行不带"defaults"哈希值?谢谢.

sie*_*ied 7

尝试这样的事情:

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