Rails makes all routes default to :: json format

Can you set all default routes to json

?

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

  scope :api, defaults: {format: :json} do
    get "/search(/:query)(/:location)" => "search#index"
  end

      

For example, all resources will user

also default tojson

resources :users

      

+3


source to share


1 answer


Use constraints

constraints format: :json do
  resources :users
end

      



or

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

      

+5


source







All Articles