I have two models : Product and Location, and Location belongs_to Product.
I use the geocoder gem, and I want to do just as in this railscast but I can't figure it out...
Part of my app/views/products/index.html.erb
<% @products.each do |p| %>
<%= p.name %>
<%= @current_location.distance_to(p.location) %>
<% end %>
Part of my app/controllers/products_controller.rb
def index
@current_location = params[:search]
if @current_location
@products = Product.with(:location).near(@current_location, order: :distance).paginate(page: params[:page])
else
@products = Product.paginate(page: params[:page])
end
end
But it renders this :
undefined method `with' for ....
Can you help me order my product by distance with geocoder ?