2013-04-28 79 views
0

我已經使用before_destroy回調來僅允許刪除最後一條記錄。我如何才能在標準腳手架的索引頁上顯示最後一條記錄的刪除鏈接?僅顯示索引頁上的最後一條記錄的刪除鏈接

<% @records.each do |record| %> 
<tr> 
<td><%= record.title %></td> 
<td><%= link_to 'Show', record %></td> 
<td><%= link_to 'Edit', edit_record_path(record) %></td> 
<% if last_record? %><td><%= link_to 'Destroy', record, method: :delete'%></td><% end %> 
</tr> 
    <% end %> 

回答

1
<% @records.each do |record| %> 
    <tr> 
    <td><%= record.title %></td> 
    <td><%= link_to 'Show', record %></td> 
    <td><%= link_to 'Edit', edit_record_path(record) %></td> 

    <% if record == @records.last %> 
     <td><%= link_to 'Destroy', record, method: :delete %></td> 
    <% end %> 
    </tr> 
<% end %> 
相關問題