Commit 722e6980 authored by John Noel's avatar John Noel

Added Post delete function

parent 041d3258
...@@ -21,6 +21,17 @@ class PostsController < ApplicationController ...@@ -21,6 +21,17 @@ class PostsController < ApplicationController
end end
end end
def destroy
@post = Post.find_by(id: params[:id])
if @post.present?
@post.destroy
alert = "You have successfully deleted a post."
else
alert = "Post not found."
end
redirect_to posts_path, alert: alert
end
def edit def edit
end end
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
<td> <td>
<%= link_to "Show", post_path(post), class: "btn btn-primary" %> <%= link_to "Show", post_path(post), class: "btn btn-primary" %>
</td> </td>
<td>
<%= link_to "Delete", post_path(post), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure you want to delete?" } %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment