ページ

2013年9月2日

Rails 3のActiveRecordで、saveしようとするとundefined method `eq' for nil:NilClassのエラーが出る問題の対処

これは、idカラムの存在しないテーブルなど、Primary Keyを設定していない場合に起きる問題となっている。

参考: http://stackoverflow.com/questions/3124290/undefined-method-eq-for-nilnilclass-with-rails-3-and-ruby-enterprise-on-ubunt

従って、以下のようにmodelでPrimary Keyを指定してやればよい。
RailsではPrimary Keyが存在しないと問題が起きることが多いので、基本的にはPrimary Keyを設定したidカラムを付けておくことを強く推奨する。
Related Posts Plugin for WordPress, Blogger...