gpt4 book ai didi

activerecord - 未定义的方法 `find_or_create'

转载 作者:行者123 更新时间:2023-12-04 13:28:27 24 4
gpt4 key购买 nike

我想使用以下命令在数据库中更新记录

Profile.find_or_create(fname: contact.FirstName, lname: contact.LastName,
company: account.Name, title: contact.Title, user_id: contact.CreatedById,
account_id: account.Id, contact_id: contact.Id, type: "contact" )

其中 Profileactiverecord model
但我得到以下错误
undefined method find_or_create for Profile class
Profile.public_methods没有显示 find_or_create方法,但 Activerecord Api定义了上述方法。

可能是什么问题?

最佳答案

它的find_or_create_by及其在Rails 3中已弃用。

使用@foo = Foo.find_by_bar("baz") || Foo.create(:bar => "baz")

关于activerecord - 未定义的方法 `find_or_create',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10481009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com