Skip to content

Commit fce1b67

Browse files
committed
built solution
1 parent d4d7946 commit fce1b67

8 files changed

Lines changed: 157 additions & 67 deletions

File tree

Gemfile.lock

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,73 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
capybara (2.5.0)
5+
mime-types (>= 1.16)
6+
nokogiri (>= 1.3.3)
7+
rack (>= 1.0.0)
8+
rack-test (>= 0.5.4)
9+
xpath (~> 2.0)
10+
coderay (1.1.0)
11+
daemons (1.2.3)
12+
diff-lcs (1.2.5)
13+
eventmachine (1.0.8)
14+
method_source (0.8.2)
15+
mime-types (2.6.2)
16+
mini_portile (0.6.2)
17+
nokogiri (1.6.6.2)
18+
mini_portile (~> 0.6.0)
19+
pry (0.10.1)
20+
coderay (~> 1.1.0)
21+
method_source (~> 0.8.1)
22+
slop (~> 3.4)
423
rack (1.5.2)
524
rack-protection (1.5.0)
625
rack
26+
rack-test (0.6.3)
27+
rack (>= 1.0)
28+
rake (10.4.2)
29+
require_all (1.3.2)
30+
rspec (3.3.0)
31+
rspec-core (~> 3.3.0)
32+
rspec-expectations (~> 3.3.0)
33+
rspec-mocks (~> 3.3.0)
34+
rspec-core (3.3.2)
35+
rspec-support (~> 3.3.0)
36+
rspec-expectations (3.3.1)
37+
diff-lcs (>= 1.2.0, < 2.0)
38+
rspec-support (~> 3.3.0)
39+
rspec-mocks (3.3.2)
40+
diff-lcs (>= 1.2.0, < 2.0)
41+
rspec-support (~> 3.3.0)
42+
rspec-support (3.3.0)
743
shotgun (0.9)
844
rack (>= 1.0)
945
sinatra (1.4.3)
1046
rack (~> 1.4)
1147
rack-protection (~> 1.4)
1248
tilt (~> 1.3, >= 1.3.4)
49+
slop (3.6.0)
50+
thin (1.6.3)
51+
daemons (~> 1.0, >= 1.0.9)
52+
eventmachine (~> 1.0)
53+
rack (~> 1.0)
1354
tilt (1.4.1)
55+
xpath (2.0.0)
56+
nokogiri (~> 1.3)
1457

1558
PLATFORMS
1659
ruby
1760

1861
DEPENDENCIES
62+
capybara
63+
pry
64+
rack-test
65+
rake
66+
require_all
67+
rspec
1968
shotgun
2069
sinatra
70+
thin
71+
72+
BUNDLED WITH
73+
1.10.2

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,31 @@ In this lab, you'll practice building nested forms in Sinatra for creating teams
1111

1212
### Make a form
1313

14-
1. Create a route that responds to a GET request at `/`.
15-
2. Create a view with a form and render it in the GET `/` route.
16-
3. The form should have fields for the `name` of a superhero team and their `motto`.
17-
4. There should be form inputs for each of the three superhero member's `name`, `power`, and `bio`.
14+
1. Create a route that responds to a GET request at `/team`.
15+
2. Create a view with a form and render it in the GET `/team` route.
16+
3. The form should have fields for:
17+
18+
+ Team name ('name')
19+
+ Coach ('coach')
20+
+ Point Guard ('pg')
21+
+ Shooting Guard ('sg')
22+
+ Power Forward ('pf')
23+
+ Small Forward ('sf')
24+
+ Center ('c')
1825

1926
It should look something like this:
2027

2128
![Imgur](http://i.imgur.com/zrbFWNE.png?1)
2229

2330
### Handle form submission
2431

25-
1. Create a route that responds to a POST request at `/teams`
32+
1. Create a route that responds to a POST request at `/team`
2633
2. Have the form send a POST request to this route.
2734
2. Upon submission, render a template that displays the submitted team data and each member's data.
2835

2936
## Final Output
3037

31-
Your params should be nested. For example, you would access the first super-hero's name as:
32-
33-
```ruby
34-
params["team"]["members"][0][name]
35-
```
36-
37-
When you post to this form you should render a page that displays the name of the team and each member of the team, along with their name, super power and bio.
38+
When you post to this form you should render a page that displays the name of the team and each member of the team.
3839

3940
Your view should display something like this:
4041

app.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@
22

33
class App < Sinatra::Base
44

5+
get '/team' do
6+
erb :team
7+
end
8+
9+
post '/team' do
10+
@name = params[:name]
11+
@coach = params[:coach]
12+
@pg = params[:pg]
13+
@sg = params[:sg]
14+
@sf = params[:sf]
15+
@pf = params[:pf]
16+
@c = params[:c]
17+
erb :newteam
18+
end
19+
520
end

spec/basic_sinatra_forms_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
describe App do
2+
3+
describe 'GET /newteam' do
4+
before do
5+
get '/team'
6+
end
7+
8+
it 'sends a 200 status code' do
9+
expect(last_response.status).to eq(200)
10+
end
11+
12+
it 'renders basketball team form' do
13+
expect(last_response.body).to include("Create a Basketball Team!")
14+
expect(last_response.body).to include("<form")
15+
end
16+
end
17+
18+
describe 'POST /team' do
19+
before do
20+
post '/team', {
21+
:name => "The Astronauts",
22+
:coach => "George Washington"
23+
:pg => "Abraham Lincoln",
24+
:sg => "James Madison",
25+
:sf => "Andre the Giant",
26+
:pf => "John Adams",
27+
:c => "Mario Batagli"
28+
}
29+
end
30+
31+
it 'sends a 200 status code' do
32+
expect(last_response.status).to eq(200)
33+
end
34+
35+
it 'displays the team info upon submission' do
36+
expect(last_response.body).to include("The Astronauts")
37+
end
38+
end
39+
end

spec/super_sinatra_forms_spec.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.

views/newteam.erb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Basketball Team</title>
6+
</head>
7+
<body>
8+
<h1>Team Name: <%=@name%></h1>
9+
<h2>Coach: <%=@coach%></h2>
10+
<h2>Point Guard: <%=@pg%></h2>
11+
<h2>Shooting Guard: <%=@sg%></h2>
12+
<h2>Small Forward: <%=@sf%></h2>
13+
<h2>Power Forward: <%=@pf%></h2>
14+
<h2>Center: <%=@c%></h2>
15+
</body>
16+
</html>
17+
18+

views/super_hero.erb

Lines changed: 0 additions & 1 deletion
This file was deleted.

views/team.erb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Basketball Team</title>
6+
</head>
7+
<body>
8+
<form method="POST" action="/team">
9+
<p> Team Name: <input type="text" name="name"> </p>
10+
<p>Coach: <input type="text" name="coach"></p>
11+
<p>Point Guard:<input type="text" name="pg"></p>
12+
<p>Shooting Guard:<input type="text" name="sg"></p>
13+
<p>Small Forward:<input type="text" name="sf"></p>
14+
<p>Power Forward:<input type="text" name="pf"></p>
15+
<p>Center: <input type="text" name="c"></p>
16+
<p><input type="submit"></p>
17+
</form>
18+
</body>
19+
</html>
220

321

0 commit comments

Comments
 (0)