Skip to content
This repository was archived by the owner on Mar 9, 2020. It is now read-only.

Commit e08cc0d

Browse files
committed
Actually do something with Projects.
1 parent 366d706 commit e08cc0d

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
class ProjectsController < ApplicationController
2+
def new
3+
@project = Project.new
4+
end
5+
def create
6+
@project = Project.new(project_params)
7+
8+
if @project.save
9+
redirect_to projects_url
10+
else
11+
render :new
12+
end
13+
end
14+
15+
def show
16+
@project = Project.find(params[:id])
17+
end
18+
19+
def index
20+
@projects = Project.all
21+
end
22+
23+
def destroy
24+
@project = Project.find(params[:id])
25+
@project.destroy
26+
redirect_to projects_url
27+
end
28+
29+
private
30+
def project_params
31+
params.require(:project).permit(:name)
32+
end
233
end

app/views/projects/index.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1>Projects</h1>
2+
3+
<ul>
4+
<% @projects.each do |project| %>
5+
<li><%= link_to project.name, project %> | <%= link_to "Destroy", project, method: :delete %></li>
6+
<% end %>
7+
</ul>
8+
9+
<p><%= link_to 'New', new_project_path %></p>

app/views/projects/new.html.erb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<h1>New Project</h1>
2+
3+
<%= form_for :project, url: projects_path do |f| %>
4+
5+
<% if @project.errors.any? %>
6+
<div class="error_messages">
7+
<h2>Form is invalid</h2>
8+
<ul>
9+
<% for message in @project.errors.full_messages %>
10+
<li><%= message %></li>
11+
<% end %>
12+
</ul>
13+
</div>
14+
<% end %>
15+
16+
<p>
17+
<%= f.label :name %><br>
18+
<%= f.text_field :name %>
19+
</p>
20+
21+
<p>
22+
<%= f.submit %>
23+
</p>
24+
25+
<% end %>
26+

app/views/projects/show.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>Project "<%= @project.name %>"</h1>
2+
3+
<p>A nice project.</p>
4+
5+
<p><%= link_to 'All projects', projects_path %></p>
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
require 'test_helper'
22

33
class ProjectsControllerTest < ActionController::TestCase
4-
# test "the truth" do
5-
# assert true
6-
# end
4+
test "should return a index" do
5+
get :index
6+
assert_response :success
7+
end
8+
test "should return a view for new" do
9+
get :new
10+
assert_response :success
11+
end
712
end

0 commit comments

Comments
 (0)