【发布时间】:2015-02-08 04:52:52
【问题描述】:
我们如何在缓存视图时隐藏敏感的或用户特定的链接,例如“编辑”或“删除”按钮?
在使用缓存的时候,不能真正使用条件句,比如:
<% if current_user.can? edit %>
<%= link_to 'Edit', edit_post_path(@post) %>
<% end %>
因为所有查看者都会看到相同的页面。
一些教程告诉我,我可以这样使用 CSS:
<% if current_user.can? edit %>
<%= link_to 'Edit', edit_post_path(@post), class: 'admin-link' %>
<% end %>
但我将如何验证编辑权限?
【问题讨论】:
标签: ruby-on-rails caching