我遇到了BCrypt密码的问题:我的User模型都设置为has_secure_password和validates_presence_of :password.
重点是BCrypt使用password,password_confirmation但在模式中只有password_digest字段.
夹具抱怨该password字段不存在.
我怎么能避免这个?
谢谢
我想以字符串形式获取 ObjectID,因为我有其他存储类型,所以我想避免在结构中使用 Primitive.ObjectID 来保持层独立。我是 Golang 新手,谢谢。
package listing
type Card struct {
ID string
Hanzi string
Pinyin string
Traducao string
}
Run Code Online (Sandbox Code Playgroud)
我的存储文件:包存储
func (m *Mongodb)GetCards() []*listing.Card {
var list []*listing.Card
collection := m.Client.Database("flashcards").Collection("cards")
cur, err := collection.Find(context.TODO(), bson.M{})
if err != nil {
log.Fatal("Erro buscando cards:", err)
}
for cur.Next(context.TODO()) {
var card listing.Card
err = cur.Decode(&card)
if err != nil {
log.Fatal("Erro decodificando documento", err)
}
list = append(list, &card)
}
return list
}
Run Code Online (Sandbox Code Playgroud)