Skip to content

Commit 8bdd203

Browse files
author
Ryan Bigg
committed
Section 4.3: Projects can now be deleted
1 parent 42fcc5e commit 8bdd203

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ticketee/app/controllers/projects_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def update
3939
end
4040
end
4141

42+
def destroy
43+
@project = Project.find(params[:id])
44+
@project.destroy
45+
46+
flash[:notice] = "Project has been destroyed."
47+
48+
redirect_to projects_path
49+
end
50+
4251
private
4352

4453
def project_params

ticketee/app/views/projects/show.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
<p><%= @project.description %></p>
44

55
<%= link_to "Edit Project", edit_project_path(@project) %>
6+
<%= link_to "Delete Project",
7+
project_path(@project),
8+
method: :delete,
9+
data: { confirm:
10+
"Are you sure you want to delete this project?"
11+
} %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "rails_helper"
2+
3+
feature "Deleting projects" do
4+
scenario "Deleting a project" do
5+
FactoryGirl.create(:project, name: "Sublime Text 3")
6+
7+
visit "/"
8+
click_link "Sublime Text 3"
9+
click_link "Delete Project"
10+
11+
expect(page).to have_content("Project has been destroyed.")
12+
13+
visit "/"
14+
15+
expect(page).to have_no_content("Sublime Text 3")
16+
end
17+
end

0 commit comments

Comments
 (0)