title: Rails: How to update multiple models together, with proper rollback (kind of manual nested attributes)
body: <p>I (for various reasons) have decided not to use <code>nested_attributes</code>. Here is my current controller:</p>
  
  <pre><code>def update
  
      # Update snippet
      @snippet.update(snippet_params)
  
      # Update hotspot
      @snippet.hotspot.update(hotspot_params)
  
      # Update text
      @snippet.text.update(medium_params_with(:text))
  
      # Update audio
      if params[:audio] {
        @snippet.audio.destroy
        @snippet.media &lt;&lt; Audio.new(medium_params_with(:audio))
      }
  
      respond_to do |format|
        if success = true #fix this up
          format.html { redirect_to @project, notice: 'Snippet was successfully updated.' }
          format.json { render :show, status: :ok, location: @snippet }
        else
          format.html { redirect_to @project, warning: 'Highlight was not updated.' }
          format.json { render json: @snippet.errors, status: :unprocessable_entity }
        end
      end
  end
  </code></pre>
  
  <p>This is more or less OK if nothing goes wrong. </p>
  
  <p>How do I wrap this into something like:</p>
  
  <pre><code>try {
    update everything
  } else {
    undo any changes I made while trying to update everything
  }
  
  if success {
    etc
  } else {
    etc
  }
  </code></pre>