Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `find_or_create'

I want to upsert record in database using following command

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"  )

where Profile is an activerecord model

but I get following error

undefined method find_or_create for Profile class

Profile.public_methods doesn't show find_or_create method but Activerecord Api defines the above method.

What might be wrong?

like image 730
Bhushan Lodha Avatar asked May 07 '12 11:05

Bhushan Lodha


1 Answers

its find_or_create_by and its deprecated in Rails 3.

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

like image 169
Omar Qureshi Avatar answered Oct 05 '22 01:10

Omar Qureshi