cancan をインストールしたところ、すぐに小さな問題が発生しました。if_can を使用できるはずですか? リンクを非表示にするアクションを適用します。これは、もちろんユーザーが作成した情報のみが編集/削除リンクを表示できるようにするためです。
同じ問題を抱えている人を他に見つけることができませんでした。誰かが私を見て助けてくれたら、それは大歓迎です。
show.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