title: ActiveRecord: Update a record if exists else create?
body: <p>Trying to implement an create if not exists else update record in Active Record.</p>
  
  <p><strong>Currently using:</strong></p>
  
  <pre><code>@student = Student.where(:user_id =&gt; current_user.id).first
  
  if @student
      Student.destroy_all(:user_id =&gt; current_user.id)
  end
  
  Student = Student.new(:user_id =&gt; current_user.id, :department =&gt; 1
  )
  Student.save!
  </code></pre>
  
  <p>What would be the correct way of updating the record if it exists or else create it? </p>