[DataMapper] datamapper undefined method `include?’ for nil:NilClass

Sinatra + DataMapper で DB にデータを保存するときに、下記のようなエラーが発生しました。

datamapper undefined method `include?' for nil:NilClass

書いたコードは、Model の new, create などで、元々あるはずのメソッドを使うと、定義されていないというエラーが発生していました。

原因は、モデルの宣言後にファイナライズ処理をしていなかったせいだったみたいです。

調べてみると、DataMapperの公式ドキュメントにちゃんと書いてありました。

Finalize Models

After declaring all of the models, you should finalize them:

DataMapper.finalize

・引用元:DataMapper – Getting started with DataMapper はてなブックマーク - DataMapper - Getting started with DataMapper

使い始める前に、ちゃんとドキュメントに目を通しておくべきですね。。。

以上です。

【参考】

#159: undefined method `include?’ for nil:NilClass in 1.2.0 but not 1.1.0 – Issues – datamapper/dm-core – GitHub はてなブックマーク - #159: undefined method `include?' for nil:NilClass in 1.2.0 but not 1.1.0 - Issues - datamapper/dm-core - GitHub

The Future is Now: DataMapper.finalize はてなブックマーク - The Future is Now: DataMapper.finalize