ability to delete conversations

main
Sebskyo 2025-03-02 08:51:43 +01:00
parent 937b3a0b6a
commit 3d7a033f08
3 changed files with 14 additions and 2 deletions

View File

@ -21,4 +21,12 @@ class ConversationsController < ApplicationController
render :index, status: :unprocessable_entity
end
end
def destroy
if @conversation.destroy
redirect_to conversations_path
else
render :show, status: :unprocessable_entity
end
end
end

View File

@ -5,8 +5,8 @@ class Ability
def initialize(user)
can :create, Conversation
can :read, Conversation, user: user
can %i[read destroy], Conversation, user: user
can :create, Message, conversation: { user: user }
can %i[index read], Message, conversation: { user: user }
can %i[index read destroy], Message, conversation: { user: user }
end
end

View File

@ -2,6 +2,10 @@
<%= link_to "list conversations", conversations_path %>
</div>
<%= form_with url: conversation_path(@conversation), method: :delete do |form| %>
<%= form.submit "delete conversation" %>
<% end %>
<ul>
<% @messages.each do |message| %>
<li><%= message.body %></li>