I have an app which allows users to post Offers based on address they choose. I would like to add the option of saving the address based on the user's current location, determined by the IP address. I'm using the ruby Geocoder gem. This code will pass but it is not saving any address to the db. I'm not sure if it's an issue with my approach or if it is not working because of the development environment. I know that other features of Geocoder e.g. distance calculations don't work in development.
current_location
is a boolean attribute of the Offer class
In the offers/_form View:
<div class="field"><br>
<%= f.label :use_current_location? %>
<%= f.check_box :current_location %>
</div>
In the OffersHelper:
def geocode_by_ip_address(offer)
if :current_location
offer.address = request.location.address
end
end
In the Offer Model:
def geo_offer
geocode_by_ip_address(offer)
end
For the purposes of the my map, gmaps4rails uses the following attributes:
def gmaps4rails_address
"#{self.address}, #{self.city}, #{self.country}"
end
However the address is not saving (have checked using the console). Would appreciate any help! Many thanks