0

私はmongodbデータベースにmongoid gemでrails3.2.3を使用しました。次のコードがあり
user = User.find_by(username: login)
ますが、投稿されたユーザー名がドキュメントのユーザー名と一致しない場合、このコードはエラーを返します。エラーは次のとおりです。この問題を解決する方法がわかりません。私を助けてください。前もって感謝します。
Problem:
Document(s) not found for class User with id(s) 5010cdc81d41c8d30b0000405. Summary: When calling User.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 5010cdc81d41c8d30b0000405 ... (1 total) and the following ids were not found: 5010cdc81d41c8d30b0000405. Resolution: Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples.


4

1 に答える 1

0


user = User.find_or_create_by(username: login)
代わりにこの使用のために
user = User.find_by(username: login)

于 2012-07-27T06:54:17.627 に答える