You must wrap those routes in a scope. Constraints unfortunately don’t work as expected in this case.
This is an example of such a block…
scope :format => true, :constraints => { :format => 'json' } do
get '/bar' => "bar#index_with_json"
end
More information can be found here: https://github.com/rails/rails/issues/5548