Routing Error: No route matches [GET] "/api/v1/courts/by_coordinates/41.89400864"

257 Views Asked by At

I have this error when I try to search in url by coordinates (saved as :latitude and :longitude in db using geocoder gem): No route matches [GET] "/api/v1/courts/by_coordinates/41.89400864" Here the code that I'm using.

module API
  module V1
    class Courts < Grape::API
      version 'v1' # path-based versioning by default
      format :json # We don't like xml anymore

      resource :courts do

        desc "Courts index"
        get do
          courts = Court.all
          present courts, with: API::Entities::Court
        end

        desc "Search by address or city"
        params do
          requires :address, :type => String, :desc => "Court Address"
        end
        get "by_address/:address" do
          courts = Court.near(params[:address])
          present courts, with: API::Entities::Court
        end

        desc "Search by address or city and range"
        params do
          requires :address, :type => String, :desc => "Court Address"
          requires :distance, :type => Integer, :desc => "Range of Distance"
        end
        get "by_address/:address/:distance" do
          courts = Court.near(params[:address], params[:distance])
          present courts.sort_by(&:distance), with: API::Entities::Court
        end

        desc "Search by coordinates"
        params do
          requires :latitude, :type => BigDecimal, :desc => "Court Latitude"
        end
        get "by_coordinates/:latitude" do
          courts = Court.near(params[:latitude])
          present courts, with: API::Entities::Court
        end

      end

    end
  end
end

I don't understand why if I use the research by address it works, but if I simply change the address with latitude params it stops to work. Someone can halp me, please? Thank you in advance!

0

There are 0 best solutions below