我想使用以下命令在数据库中更新记录
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" )
其中
Profile
是activerecord 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/