Rails - Render and/or redirect were called multiple times in this action
<p>I have a Rails page that lets the user select one or more records.</p>

<p>This is the controller action:</p>

<pre><code>  def addinvtimes
    @invoice = params[:invtimes][:invoice_id]
    if params[:event_ids] != nil
      params[:event_ids].each do |i|
        newinvtime = Invtime.new(
            linetype_id: 1,
            invoice_id: @invoice,
            event_id: i.to_i
        )
        if newinvtime.save
          respond_to do |format|
            if newinvtime.save
              format.html { redirect_to invoice_path(@invoice), :notice =&gt; 'Invoice Item was successfully added.' }
            else
              format.html { redirect_to invoice_path(@invoice), :notice =&gt; 'ERROR.' }
            end
          end
        end
      end
    end
  end
</code></pre>

<p>There error I get is:</p>

<pre><code>Render and/or redirect were called multiple times in this action
</code></pre>

<p>How can I code to not call the redirect multiple times?</p>