Search code examples
ruby-on-railsrgeo

Method not defined in production


I have a project with PostGIS integration through RGeo gem. Rails 4, ruby 2.1.

RGeo has standard method contains? which checks is point is located in polygon. Everything is fine in development (on MacOS X). But when I push my code to production server (Ubuntu 12.04) I have this error:

ActionView::Template::Error (Method Geometry#contains? not defined.):
app/models/address.rb:28:in `block in define_courier_area'
app/models/address.rb:28:in `define_courier_area'

The code is very simple. I just need to return an array of all CourierArea instances, where are Address coords located.

address.rb

class Address < ActiveRecord::Base
  def define_courier_area # HAVE TO BE REFACTORED
    arr = []
    CourierArea.all.each { |ca| arr << ca if ca.poly.contains?(self.coords)}
    arr.first if arr.first
  end
end

I suppose, production environment can't obtain access to contains? method, which is provided by RGeo gem. How can I solve this problem? Maybe I should insert require 'some_rgeo_file'?


Solution

  • Problem has been solved.

    RGeo uses some external libraries. For geometry calculations (distance, area, point-in-polygon) this library is GEOS. When I tried to invoke contains? RGeo was seeking for GEOS but it was not installed.

    Moreover there is an RGeo method RGeo::Geos.supported? for checking GEOS availability. If it will return false, you probably has no GEOS installed or RGeo has problems with connecting with it. If it will return true – boya! you can use geometry calculation methods!