How does one fragment cache comments with a session information? For example:
<% cache "song_#{@song.id}_comments" do %>
<ul>
<% @comments.each do |comment| %>
<li class="clearfix">
<p><%= comment.comment %></p>
<% if can? :destroy, comment %>
<span>·</span><%= link_to 'delete', comment_path(comment), :confirm => 'Are you sure?', :method => :delete, :remote => true %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
A delete link displays if a user owns the comment. But since, this is cached. It shouldn’t show up for other users.
I think it is not possible to have session-based logic in the fragment cache unless you make that information part of the key, which kind of defeats the purpose of caching.
One possible way is to use client-based logic to add delete-link dynamically if the comment is owned by the user.
For example, you can embed a hidden_field – owner_id for each comment. And then, for each rendering, apart from the cached comments (with owner-ids), you can have another hidden field – current user id. JS can then add the delete link for all comments that the user is the owner of.