문제

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.

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top