I am fairly new to rails and trying to learn rails by creating some
projects on my own. I am trying to perform a geo search on a
restaurant model and I am using geokit for that. My model stores the
latitude and longitude for the location.
I am searching for the specified location entered by the user and
getting all the restaurants that are near that location. However I
would also like to apply another filter on the returned result like
returning the restaurant that only serves italian (for example). Here
is a snippet of the code that I using.
//Using geokit find method to return the restaurants within 2
miles of the specified address
@restaurants = Restaurant.find(:all, :origin => @location, :within
=> 2)
//finally getting the restaurants that serve the user specified
cuisine
@restaurants = @restaurants.where("cuisine like ?",
params[:cuisine]) if params[:cuisine]
This results in an " undefined method `where' " error.
I am not able to figure out how can I get this to work. I am using
rails3 and ruby 1.9.2.
I am fairly new to rails and trying to learn rails by creating some
projects on my own. I am trying to perform a geo search on a
restaurant model and I am using geokit for that. My model stores the
latitude and longitude for the location.
I am searching for the specified location entered by the user and
getting all the restaurants that are near that location. However I
would also like to apply another filter on the returned result like
returning the restaurant that only serves italian (for example). Here
is a snippet of the code that I using.
//Using geokit find method to return the restaurants within 2
miles of the specified address
@restaurants = Restaurant.find(:all, :origin => @location, :within
=> 2)
//finally getting the restaurants that serve the user specified
cuisine
@restaurants = @restaurants.where(“cuisine like ?”,
params[:cuisine]) if params[:cuisine]
Restaurant.where(:cuisine => params[:cuisine]) will return all the
Restaurants that that have the cuisine. However I am trying to filter
the returned results from @restaurants = Restaurant.find(:all, :origin
=> @location, :within
=> 2) . Hence I am trying to apply the where condition on
@restaurants, using @restaurants = @restaurants.where("cuisine
like ?", params[:cuisine]). But that doesn't work.
[...] Hence I am trying to apply the where condition on
@restaurants, using @restaurants = @restaurants.where("cuisine
like ?", params[:cuisine]). But that doesn't work.
Once you've gotten @restaurants you are not querying the DB anymore,
hence the 'where' should give you an error. @restaurants is in essence
an array and will not have a 'where' method in it unless you add it.
Look into the Ruby methods for Array (http://ruby-doc.org/core/classes/
Array.html) and you'll probably find what you're looking for.