Forum: Ruby on Rails geokit - using :through to connect models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fddbb3cd16868f4741c2e86ef015a639?d=identicon&s=25 Sergio T. Ruiz (sergio101)
on 2009-02-23 08:12
hello..

i am currently trying to use :through to attach two of my models
together using geokit. for some reason, i am running into a problem:

ArgumentError: Unknown key(s): as

i have two models, one that is geocoded, and one that belongs to that
model. the models look like:

,----[ employer.rb ]
| class Employer < ActiveRecord::Base
|   acts_as_mappable
|   before_validation_on_create :geocode_address
|
|   has_many :internships
|   belongs_to :account
|   belongs_to :role
|
|  private
|   def geocode_address
|     geo=GeoKit::Geocoders::MultiGeocoder.geocode(address1 + " " + city + " " + state + " 
" + zip)
|     errors.add(:address, "Could not Geocode address") if !geo.success
|     self.lat, self.lng = geo.lat,geo.lng if geo.success
|   end
|
| end
`----

and an internship:

,----[ internship.rb ]
| class Internship < ActiveRecord::Base
|   has_many :internship_categories
|   belongs_to :employer, :polymorphic => true
|   acts_as_mappable :through => :employer
| end
`----

it seems like there is an intermediary object in the docuements called
':locatable' that connects the the two together, but i just can't get
how that is being called, or what i am supposed to do with it.

no matter where i put it, i end up with this error:

ArgumentError: Unknown key(s): as

if i remove: ":as => :locatable" i end up with a problem in that the
model doesn't have :lat or :lng, which makes me think that
the :through is not working at all.

please let me know how to attack this..

thanks!
92497f51734ed56687928d5fd68d870a?d=identicon&s=25 Sarah Mei (Guest)
on 2009-02-23 19:12
(Received via mailing list)
I think your trouble here is with the polymorphic association. (Why do
you need it - is there another model that has_one or has_many
:internships :as => :employer?)

Try either removing :polymorphic => true if you don't need it, or
adding :as => :employer to the Employer's has_many :internships line.

http://wiki.rubyonrails.org/rails/pages/Understand...

On Sun, Feb 22, 2009 at 11:12 PM, Sergio Ruiz
Fddbb3cd16868f4741c2e86ef015a639?d=identicon&s=25 Sergio T. Ruiz (sergio101)
on 2009-02-24 16:34
thanks for your help!

i am  gonna have to look into this a little bit more to get my head
around this..

thanks!
This topic is locked and can not be replied to.