Using a rail geocoder when an object has 2 sets of coordinates

Rails 3.1, Ruby 1.9.3

So, I have two models, both have two sets of coordinates.

The first model Loadhas from_lat/lngas well to_lat/lng.
The second model, Trucks, has current_lat/lngas well destination_lat/lng.

What I'm trying to do is find all the results that have either current_lat/lngor destination_lat/lngfrom the Truck model next to the to_lat / lng of the Load model.

My track model looks something like this:

class Load < ActiveRecord::Base  

  has_many :trucks

  geocoded_by :custom_geocode  

  after_validation :custom_geocode

  def custom_geocode  
    var = Geocoder.coordinates([from_city,from_state].compact.join(','))  
    var2 = Geocoder.coordinates([to_city,to_state].compact.join(','))  
    self.from_lat = var.first  
    self.from_lng = var.last  
    self.to_lat = var2.first  
    self.to_lng = var2.last  
  end
end

In my opinion, I have:

<% for truck in @trucks %>  
  <li><%= truck.destination_lat %></li>  
<% end %>

I am currently using this in my load_controller:

def show
  @load = Load.find(params[:id])
  @trucks = Truck.near([@load.from_lat, @load.from_lng], 100, :order => "distance")

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @load }
  end
end

The error I get is:
PG::Error: ERROR: column trucks.latitude does not exist

, , :latitude :longitude. , (destination_lat/lng current_lat/lng) Truck?

+5

All Articles