路由有如下代码:
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' }
是否可以使用 1 个字符串为所有资源设置默认格式,每行不带“默认值”散列?谢谢。
最佳答案
尝试这样的事情:
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
关于ruby-on-rails - 如何在 Rails 中设置路由的默认格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21016987/