I have a model, Offers, and am trying to obtain the ip address from the user and geocode the coordinates by latitude and longitude. The gem documentation indicates that where the ip address is known the code should be:
Model:
geocoded_by :ip_address, :latitude => :latitude, :longitude => :longitude
However I don't have the ip address saved initially so I changed it to this:
if :current_location
self.ip_address = request.ip
geocoded_by :ip_address, :latitude => :latitude, :longitude => :longitude
end
request.ip is a method from ActionView I believe so can't be called from the Model. I have tested this as a helper method and it returns the local:host address. But when I try and save it in this format it is not saving anything to the model.
What is the neatest way to save the ip_address to the model so it can be used in this format? Should it be extracted to a helper method? Is there a way to includeor require the right module in the model?
For reference the gem guide is here: http://www.rubygeocoder.com
All help appreciated, thanks.