Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

module FormsLab
class App < Sinatra::Base
get '/' do
erb :root
end

# code other routes/actions here
get '/new' do
erb :'pirates/new'
end

post '/pirates' do
@pirate = Pirate.new(params[:pirate])

params[:pirate][:ships].each do |details|
Ship.new(details)
end
@ships = Ship.all

erb :'pirates/show'
end

end
end
16 changes: 15 additions & 1 deletion app/models/pirate.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
class Pirate
end
attr_reader :name, :weight, :height

PIRATES = []

def initialize(params)
@name = params[:name]
@weight = params[:weight]
@height = params[:height]
PIRATES << self
end

def self.all
PIRATES
end
end
21 changes: 20 additions & 1 deletion app/models/ship.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
class Ship
end
attr_reader :name, :type, :booty

@@all = []

def initialize(params)
@name = params[:name]
@type = params[:type]
@booty = params[:booty]
@@all << self
end

def self.all
@@all
end

def self.clear
@@all = []
end
end

26 changes: 25 additions & 1 deletion views/pirates/new.erb
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
<h1>Make your form here</h1>
<form action='/pirates' method="POST">
<h2>Pirate</h2>
<label for="pirate_name">Name</label><br>
<input id="pirate_name" type="text" name="pirate[name]" /><br>
<label for="pirate_weight">Weight</label><br>
<input id="pirate_weight" type="text" name="pirate[weight]" /><br>
<label for="pirate_height">Height</label><br>
<input id="pirate_height" type="text" name="pirate[height]" /><br><br>

<h2>Ship(s)</h2>
<label for="ship_name_1">Name</label><br>
<input id="ship_name_1" type="text" name="pirate[ships][][name]" /><br>
<label for="ship_type_1">Type</label><br>
<input id="ship_type_1" type="text" name="pirate[ships][][type]" /><br>
<label for="ship_booty_1">Booty</label><br>
<input id="ship_booty_1" type="text" name="pirate[ships][][booty]" /><br><br>

<label for="ship_name_2">Name</label><br>
<input id="ship_name_2" type="text" name="pirate[ships][][name]" /><br>
<label for="ship_booty_2">Type</label><br>
<input id="ship_type_2" type="text" name="pirate[ships][][type]" /><br>
<label for="ship_booty_2">Booty</label><br>
<input id="ship_booty_2" type="text" name="pirate[ships][][booty]" /><br>
<input type="submit" value="Submit">
</form>
18 changes: 14 additions & 4 deletions views/pirates/show.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<h1>Display your Pirate here</h1>

<h1>Pirates</h1>

<h2>Display your first ship here</h2>
<div class="pirate">
<h3>Name: <%= @pirate.name %></h3><br>
<h4>Weight: <%= @pirate.weight %> pounds</h4><br>
<h4>Height: <%= @pirate.height %> inches</h4>
</div><br>


<h2>Display your second ship here</h2>
<h1>Ships</h1>
<% @ships.each do |ship| %>
<div class="ship">
<p>Name: <%= ship.name %></p><br>
<p>Type: <%= ship.type %></p><br>
<p>Booty: <%= ship.booty %></p>
</div><br>
<% end %>