railsの勉強 リンク上のクリックをフック

> つぎは、クリックが多いものから並べるとか、ボタンを押すと
> クリックが多いものから並べるというふうにしたいのだが、
> どうやったらできるのだろう?
現状のlist.rhtmlは、以下の通り。


<h2>My bookmarks</h2>

<table>
<!-- Columns order is as follows: -->
<!-- | Col time | Title | Url | Description | Op. | -->
<tr>
<th>追加日付</th>
<th>タイトル</th>
<th>説明</th>
<th>操作</th>
</tr>

<% lineno = 0; line = "even" %>
<% for bookmark in @bookmarks %>
<tr class="<%= line %>">
<% col_time = bookmark.col_time %>
<td width="10%" align="center"><%= col_time.strftime("%y/%m/%d") %></td>
<% url = bookmark.url %>
<td width="30%"><a href=<%= url %> target="_new"><%= bookmark.title %></a></td>
<td><%= bookmark.description %></td>
<td width="10%" align="center">
<%= link_image_to '/images/attr.png', :action => 'show', :id => bookmark %>
<%= link_image_to '/images/edit.png', :action => 'edit', :id => bookmark %>
<%= link_image_to '/images/delt.png', { :action => 'destroy', :id => bookmark }, :confirm => 'Are you sure?', :post => true %></td>
</tr>
<% lineno = (lineno == 0) ? 1 : 0 %>
<% line = (lineno == 0) ? "even" : "odd" %>
<% end %>
</table>
(以下略)

つまり、(わかりにくいけど)タイトル文字列にurlフィールドの内容で<a>タグをかぶせて、タイトル文字をクリックするとそこにジャンプする(新しいウィンドウを開く)ようにしてある。
link_toメソッドの引数は、表示文字列とそこでクリックを検知したときに呼ばれるcontrollerのメソッド名などで、URLは指定できない(?)し、できてもちょっと違う。
マニュアルを見ると、redirect_toというActionController::Baseクラスのメソッドがあって、つまり、これを呼び出すメソッドをcontrollerにつくって、link_toでは、そのメソッドを指定すればできそう。

<td width="30%">
<a href=<%= url %> target="_new"><%= bookmark.title %>
</a></td>
の部分を

<td width="30%">
<%= link_to bookmark.title,
{:action => 'redirect_hook', :id => bookmark} %>
</td>
と変更して、admin_controller.rbの最後に

def redirect_hook
@bookmark = Bookmark.find(params[:id])
# TODO
# このURLの参照カウントを増やす。(DBに反映)
redirect_to @bookmark.url
end
を追加することで、リンクでのクリックを検知するように修正。
新しいブラウザのウィンドウができないけど、右クリックメニューで我慢することにする。
つぎは、DBテーブルを修正して、リンク数を記録できるようにしたい。