シリアル化メソッドを IPAddress モジュールにモンキー パッチすることで、Mongoid ドキュメントのカスタム フィールドとしてIPAddressを使用しようとしていますが、取得できないようです...
class Computer
include Mongoid::Document
field :ip_address, type: IPAddress
end
module IPAddress
def mongoize
to_string
end
def self.mongoize(object)
object.to_string
end
def self.demongoize(string)
IPAddress.new string
end
def self.evolve(object)
object.to_string
end
end
これが私が今得たものです...しかし、私は他の多くの方法を試しましたが、機能する方法を見つけることができません. どんな助けでも大歓迎です!