Ruby on rails rails 3 mongoid和国家宝石

Ruby on rails rails 3 mongoid和国家宝石,ruby-on-rails,ruby-on-rails-3,rubygems,mongoid,country-codes,Ruby On Rails,Ruby On Rails 3,Rubygems,Mongoid,Country Codes,我想使用我在这里找到的国家宝石,而不是创建一个单独的模型 它可以很好地从中继承,但我也希望能够有其他类属于它 这可能吗?如下图所示。是否有一些方法可以用来提供子类的键 class国家String ##关系 有很多城市吗 有很多:评论,如::可评论 初始化后的def ISO3166::Country.find_Country_by_alpha3(self.Country_id) 终止 终止 对我来说,最好的做法不是在您的案例中使用有许多,而是使用Mongoid查询创建您想要的方法 class C

我想使用我在这里找到的国家宝石,而不是创建一个单独的模型

它可以很好地从中继承,但我也希望能够有其他类属于它

这可能吗?如下图所示。是否有一些方法可以用来提供子类的键

class国家
目前,我得到了Country:Class的NoMethodError:undefined方法'has_many'

或者在初始化对象后,以某种方式从gem中包含/继承属性

class Country# < ISO3166::Country
  include Mongoid::Document

  #field :name, :type => String
  field :country_id, :type => String

  ##RELATIONS
  has_many :cities
  has_many :reviews, as: :reviewable


  def after_initialize
    ISO3166::Country.find_country_by_alpha3(self.country_id)
  end


end
class国家#String
字段:country\u id,:type=>String
##关系
有很多城市吗
有很多:评论,如::可评论
初始化后的def
ISO3166::Country.find_Country_by_alpha3(self.Country_id)
终止
终止

对我来说,最好的做法不是在您的案例中使用
有许多
,而是使用Mongoid查询创建您想要的方法

class Country# < ISO3166::Country
  include Mongoid::Document

  #field :name, :type => String
  field :country_id, :type => String

  ##RELATIONS
  has_many :cities
  has_many :reviews, as: :reviewable


  def after_initialize
    ISO3166::Country.find_country_by_alpha3(self.country_id)
  end


end