Bhu*_*dha 6 activerecord ruby-on-rails-3.2
我想使用以下命令在数据库中upup记录
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" )
Run Code Online (Sandbox Code Playgroud)
这里Profile是一个activerecord model
但我得到以下错误
undefined method find_or_create for Profile class
Run Code Online (Sandbox Code Playgroud)
Profile.public_methods没有显示find_or_create方法,但Activerecord Api定义了上述方法.
可能有什么问题?
Oma*_*shi 10
它find_or_create_by和它在Rails 3中被弃用了.
使用 @foo = Foo.find_by_bar("baz") || Foo.create(:bar => "baz")