I am using geocoder and the devise gem. And i am trying to get coupons near user’s location
Coupon Model
def index
if params[:search].present?
@coupons = Coupon.near([user_long, user_lat], 50, :order => :distance)
else
@coupons = Coupon.all
end
end
Application Helper
I have defined the user_long and user_lat
def user_long
current_user.longitude
end
def user_lat
current_user.latitude
end
Devise Gem
I have tried to use the devise gem helper to get the values like so
Coupon Model
def index
if params[:search].present?
@coupons = Coupon.near([current_user.longitude, current_user.latitude], 50, :order => :distance)
else
@coupons = Coupon.all
end
end
I am hitting the walls and celling with this. Can someone help out, i know this is newbie question for but i can’t solve it so save my life?
My mistake was that i that i had the longitude before that latitude, It was taking away the logic
This works.