Active Record で create if not exists else 更新レコードを実装しようとしています。
現在使用中:
@student = Student.where(:user_id => current_user.id).first
if @student
Student.destroy_all(:user_id => current_user.id)
end
Student = Student.new(:user_id => current_user.id, :department => 1
)
Student.save!
レコードが存在する場合、またはレコードを作成する場合、レコードを更新する正しい方法は何ですか?