I'm trying to build in logic that would allow a User to be the only one to be able to delete a post they make. I am using CanCanCan and followed their documentation as found on github.
This is my code
in my ability.rb
class Ability
include CanCan::Ability
def initialize(user)
can :destroy, Status, :user_id => user.id
end
end
in my application controller
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include CanCan::ControllerAdditions
end
where i try and utilize cancancan
<% if can? :destroy, @status %>
<%= link_to "Edit", edit_status_path(status) %> |
<%= link_to "Delete", status, method: :delete, data: {confirm: "Are you sure you want to delete this status?"} %>
<% end %>
neither the "Edit" or "Delete" link shows up with my current if condition. Can anyone help me solve this?
Aucun commentaire:
Enregistrer un commentaire