I have a list table with a listing model and the lists_controller class. I wrote a method that requires 2 parameters: latitude and longitude. He then retrieves the lists located around this coordinate for about 5 km. In lists_controller, this is the method I wrote:
def around lat = params[:latitude] long = params[:longitude] @surroundings = Listing.where("latitude = ? and longitude = ?", lat, long) end
What I would like to do is set the URL in the routes.rb file, which, when the client browser is called, will provide latitude and longitude in the form of 2 parameters. No: the id parameter can be provided, because the client browser does not know the identifier, and, moreover, there can be no record in the database that exactly matches the coordinates. Remember that Im only looking to search lists around specific coordinates.
So how to write this in the routes file?
Here is the result of my rake routes command
listings / listings
And this is what the routes.rb file looks like:
Businesses::Application.routes.draw do root to: 'listings#index', as: 'listings' resources :listings match ':controller(/:action(/:id))(.:format)'
Here is what I was hoping to use as a url string from a client browser:
http:
Any help would be appreciated
source share