title: Link to an external URL and also run controller method
body: <p>I'm trying to get my head around Rails routes/controllers and ajax and I'm in need of a bit of direction to help solve my current challenge...</p>
  
  <p>I'm rendering a list of links from the database, each contains a 'last_visited' field.</p>
  
  <p>As a user, I'd like to click a link and for it to open in a new tab (target = _blank). On doing so the link's 'last_visited' field will be updated with the current time and date.</p>
  
  <p>Here's what I have so far:</p>
  
  <p>View</p>
  
  <pre><code>%li.feed
    = link_to(visit_path(:id =&gt; feed.id), :method =&gt; :put, :target =&gt; '_blank') do
      .title=feed.title
  </code></pre>
  
  <p>Route</p>
  
  <pre><code>match "/feeds" =&gt; "pages#visit_feed", :as =&gt; :visit
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>def visit_feed
   @feed = Feed.find(params[:id])
   @feed.update_visit_date!
  
   respond_to do |format|
     format.html { redirect_to @feed.url }
     format.json { head :no_content }
   end
  end
  </code></pre>
  
  <p>The 'last_visited' field update is handled in the model.</p>
  
  <p>While this works, a new tab opens with the link and the last_visited date is updated. The anchor tag is rendered like this (note the href):</p>
  
  <pre><code>&lt;a href="/feeds?id=7" data-method="put" rel="nofollow" target="_blank"&gt;
    // content
  &lt;/a&gt;
  </code></pre>
  
  <p>I'm using the controller format.html to redirect_to, which is causing (I assume) undesirable behaviour, in that when I "cmd + click" a new tab doesn't open in the background as I stay on the page (sounds trivial but it's a very common and crucial user behaviour for what I'm building).</p>
  
  <p>So in short, I'm keen to hear about an alternative/recommended approach... I've been considering using ajax to update the last_visited field rather than controller/model, is this recommended? How would I go about this?</p>
  
  <p>Any help/thoughts/direction is much appreciated. Thanks for your time.</p>