Problem using GeoKit plugin from rake task

I’m still learning rails and I’ve run into a problem that has me
baffled and google hasn’t been able to help.

I’m using the GeoKit plugin to handle the geocoding of one of my
models. The model has a method called do_geocode(addr) that takes an
address string (addr), does the geocoding and assigns the appropriate
attributes based on the response. I’ve tested this quite a bit using
my web interface and have had no problems. Now, though, I’m trying to
do geocoding from a rake task, and this method always mysteriously
fails. The rake task reads in an address string from a file and calls
go_geocode on the model object.

Are rake tasks not able to utilize the full functionally of models
that have plugin functionality mixed in? The rake task code is
included below:

require ‘csv’

namespace :util do
desc ‘Import CSV file of stuff’
task(:import => :environment) do
CSV::Reader.parse(File.open(’./lib/tasks/test.csv’, ‘r’)) do |row|
store = Store.new do |c|
c.name = row[0]
c.phone = row[1]
addr = row[2]
c.do_geocode(addr)
end

  if store.valid? # It is never valid because do_geocode always

fails
puts ‘Store is valid’
else
store.errors.each_full{ |msg| puts msg }
end

end

end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs