Skip to content

Commit 9279a78

Browse files
author
Ryan Bigg
committed
Section 3.4.3: 'Create a new project' feature complete.
1 parent 10ac2fe commit 9279a78

File tree

14 files changed

+109
-1
lines changed

14 files changed

+109
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the projects controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class ProjectsController < ApplicationController
2+
def index
3+
end
4+
5+
def new
6+
@project = Project.new
7+
end
8+
9+
def create
10+
@project = Project.new(project_params)
11+
if @project.save
12+
flash[:notice] = "Project has been created."
13+
redirect_to @project
14+
else
15+
# nothing, yet
16+
end
17+
end
18+
19+
def show
20+
@project = Project.find(params[:id])
21+
end
22+
23+
private
24+
25+
def project_params
26+
params.require(:project).permit(:name, :description)
27+
end
28+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ProjectsHelper
2+
end

ticketee/app/models/project.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Project < ActiveRecord::Base
2+
end

ticketee/app/views/layouts/application.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<%= csrf_meta_tags %>
88
</head>
99
<body>
10-
10+
<% flash.each do |key, value| %>
11+
<div class='flash' id='<%= key %>'>
12+
<%= value %>
13+
</div>
14+
<% end %>
1115
<%= yield %>
1216

1317
</body>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= link_to "New Project", new_project_path %>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>New Project</h2>
2+
<%= form_for(@project) do |f| %>
3+
<p>
4+
<%= f.label :name %><br>
5+
<%= f.text_field :name %>
6+
</p>
7+
<p>
8+
<%= f.label :description %><br>
9+
<%= f.text_field :description %>
10+
</p>
11+
<%= f.submit %>
12+
<% end %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h2><%= @project.name %></h2>

ticketee/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Rails.application.routes.draw do
2+
root "projects#index"
3+
resources :projects
24
# The priority is based upon order of creation: first created -> highest priority.
35
# See how all your routes lay out with "rake routes".
46

0 commit comments

Comments
 (0)