別のモデルを作成する代わりに、ここで見つけたcountries gemを使用したいと思います。
継承しても問題なく動作しますが、他のクラスを属することができるようにしたいと考えています。
これは可能ですか?IEは以下のようなものです。子クラスにキーを提供するために使用できる方法はありますか?
https://github.com/hexorx/countries
class Country < ISO3166::Country
#include Mongoid::Document
#RELATIONS
has_many :cities
has_many :reviews, as: :reviewable
end
現時点では、NoMethodError: undefined method `has_many' for Country:Class が発生します
または、オブジェクトが初期化された後に宝石から属性を含める/継承する方法はありますか?
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