Skip to content

Commit 1f820f8

Browse files
author
Ryan Bigg
committed
Section 3.4.3: 'Create a new project' feature complete.
1 parent 98ee7a5 commit 1f820f8

File tree

14 files changed

+116
-53
lines changed

14 files changed

+116
-53
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
12+
if @project.save
13+
flash[:notice] = "Project has been created."
14+
redirect_to @project
15+
else
16+
# nothing, yet
17+
end
18+
end
19+
20+
def show
21+
@project = Project.find(params[:id])
22+
end
23+
24+
private
25+
26+
def project_params
27+
params.require(:project).permit(:name, :description)
28+
end
29+
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
</head>
99
<body>
1010

11+
<% flash.each do |key, message| %>
12+
<div class='flash' id='<%= key %>'>
13+
<%= message %>
14+
</div>
15+
<% end %>
16+
1117
<%= yield %>
1218

1319
</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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
8+
<p>
9+
<%= f.label :description %><br>
10+
<%= f.text_field :description %>
11+
</p>
12+
13+
<%= f.submit %>
14+
<% 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 & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
11
Rails.application.routes.draw do
2-
# The priority is based upon order of creation: first created -> highest priority.
3-
# See how all your routes lay out with "rake routes".
2+
root 'projects#index'
43

5-
# You can have the root of your site routed with "root"
6-
# root 'welcome#index'
7-
8-
# Example of regular route:
9-
# get 'products/:id' => 'catalog#view'
10-
11-
# Example of named route that can be invoked with purchase_url(id: product.id)
12-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13-
14-
# Example resource route (maps HTTP verbs to controller actions automatically):
15-
# resources :products
16-
17-
# Example resource route with options:
18-
# resources :products do
19-
# member do
20-
# get 'short'
21-
# post 'toggle'
22-
# end
23-
#
24-
# collection do
25-
# get 'sold'
26-
# end
27-
# end
28-
29-
# Example resource route with sub-resources:
30-
# resources :products do
31-
# resources :comments, :sales
32-
# resource :seller
33-
# end
34-
35-
# Example resource route with more complex sub-resources:
36-
# resources :products do
37-
# resources :comments
38-
# resources :sales do
39-
# get 'recent', on: :collection
40-
# end
41-
# end
42-
43-
# Example resource route with concerns:
44-
# concern :toggleable do
45-
# post 'toggle'
46-
# end
47-
# resources :posts, concerns: :toggleable
48-
# resources :photos, concerns: :toggleable
49-
50-
# Example resource route within a namespace:
51-
# namespace :admin do
52-
# # Directs /admin/products/* to Admin::ProductsController
53-
# # (app/controllers/admin/products_controller.rb)
54-
# resources :products
55-
# end
4+
resources :projects
565
end

0 commit comments

Comments
 (0)