Ruby on rails 3 在Rails控制台中指定多态作为可映射模型

Ruby on rails 3 在Rails控制台中指定多态作为可映射模型,ruby-on-rails-3,geokit,rails-console,Ruby On Rails 3,Geokit,Rails Console,我有一个多态位置模型: class Location < ActiveRecord::Base acts_as_mappable before_validation :geocode_address, :on => :create belongs_to :locatable, :polymorphic => true end 我没有机会将位置分配给用户 如果我删除'acts\U as\U MAPABLE:TO=>:location'指令,我可以毫无问题地分配位置

我有一个多态位置模型:

class Location < ActiveRecord::Base
  acts_as_mappable
  before_validation :geocode_address, :on => :create
  belongs_to :locatable, :polymorphic => true
end 
我没有机会将位置分配给用户

如果我删除'acts\U as\U MAPABLE:TO=>:location'指令,我可以毫无问题地分配位置:

l = Location.create(:full_address=>'123 maple street, chicago, il')
u = User.create(:username=>'foo')
u.location = l

位置的定义需要在其使用之前:

class User < ActiveRecord::Base
  has_one :location, :as => :locatable
  acts_as_mappable :through => :location
end 
class用户:locatable
作为可映射:通过=>:位置
结束

位置的定义需要在使用之前:

class User < ActiveRecord::Base
  has_one :location, :as => :locatable
  acts_as_mappable :through => :location
end 
class用户:locatable
作为可映射:通过=>:位置
结束
class User < ActiveRecord::Base
  has_one :location, :as => :locatable
  acts_as_mappable :through => :location
end