ActiveRecord: Update a record if exists else create?

后端 未结 7 1713
北荒
北荒 2020-12-30 19:04

Trying to implement an create if not exists else update record in Active Record.

Currently using:

@student = Student.where(:user_id          


        
7条回答
  •  既然无缘
    2020-12-30 19:43

    You may be looking for first_or_create or something similar:

    http://guides.rubyonrails.org/v3.2.17/active_record_querying.html#first_or_create

提交回复
热议问题