The find_or_create_by method is a combination of the find method and the create method. Search the table for records that meet the conditions passed in the argument A method that gets the corresponding record if it exists, and creates it if it doesn't.
** Model .find_or_create_by (search condition) **
Example: To get a record with name "suzuki" from the users table, or create it if it doesn't exist
User.find_or_create_by(name: "suzuki")
Recommended Posts