Rails make all routes default to format: :json

后端 未结 2 566
天命终不由人
天命终不由人 2021-01-18 08:50

Can you make all routes default to json?

I have the following for an api scope but am wondering if you can do the same for the global scope?

         


        
2条回答
  •  既然无缘
    2021-01-18 09:49

    Use constraints

    constraints format: :json do
      resources :users
    end
    

    or

    resources :users, :defaults => { :format => 'json' }
    

提交回复
热议问题