我刚刚安装了 cancan,我遇到了一个快速的小问题。我应该可以使用 if_can 吗?应用操作来隐藏链接。只有用户创建的信息才能查看编辑/删除链接。
我一直无法找到遇到同样问题的其他人。如果有人可以看看并帮助我,将不胜感激。
显示.html:
<div id="photos">
<% for photo in @gallery.photos %>
<div class="photo">
<%= image_tag photo.image_url(:thumb).to_s %>
<div class="name"><%= photo.name %></div>
<div class="actions">
<% if can? :update, @photo %>
<%= link_to "edit", edit_photo_path(photo) %> |
<% end %>
<% if can? :remove, @photo %>
<%= link_to "remove", photo, :confirm => 'Are you sure?', :method => :delete %>
<% end %>
</div>
</div>
<% end %>
<div class="clear"></div>
</div>
<p>
<%= link_to "Add a Photo", new_photo_path(:gallery_id => @gallery) %>
|
<%= link_to "Remove Gallery", @gallery, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View Galleries", galleries_path %>
</p>
能力.rb
class Ability
include CanCan::Ability
def initialize(user)
can :read, :all
end
end