Question

I have a rails model that uses geokit that includes the line acts_as_mappable :auto_geocode=>true which calls something like before_validation :geocode_address, :on => :create. However, my issue is that I have a seeds file for my development database that calls th Rails model and then calls this on create, which calls an external API and fails when I'm not connected to the internet. What approaches are available to me?

It would be nice if the approach covered both this case and when I run my tests as well, but I already have a work around for the tests that isn't very pretty.

Was it helpful?

Solution

You could try something like this:

# /db/seeds.rb

ModelName.class_eval { acts_as_mappable(:auto_geocode => false) }

# Create seed models...

ModelName.class_eval { acts_as_mappable(:auto_geocode => true) }

This might even work,

ModelName.acts_as_mappable(:auto_geocode => false)

EDIT:

Another solution would be the skip_callback method:

ModelName.skip_callback(:validation, :before, :auto_geocode_address)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top