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?
scope :api, defaults: {format: :json} do
get "/search(/:query)(/:location)" => "search#index"
end
For example all user
resources would also default to json
resources :users
Use constraints
constraints format: :json do
resources :users
end
or
resources :users, :defaults => { :format => 'json' }
According to Rails docs, in your config/routes.rb
file:
defaults format: :json do
resources :photos
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With