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 #12

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

Done #12

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
17 changes: 16 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
module FormsLab
class App < Sinatra::Base

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

get '/new' do
erb :'pirates/new'
end

post '/pirates' do
@pirate = Pirate.new(params[:pirate])
params[:pirate][:ships].each do |ship|
Ship.new(ship)
end
@ship1 = Ship.all[0]
@ship2 = Ship.all[1]
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_accessor :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
20 changes: 19 additions & 1 deletion app/models/ship.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
class Ship
end
attr_accessor :name, :type, :booty

SHIPS = []

def initialize(args)
@name = args[:name]
@type = args[:type]
@booty = args[:booty]
SHIPS << self
end

def self.all
SHIPS
end

def self.clear
SHIPS.clear
end
end
15 changes: 14 additions & 1 deletion views/pirates/new.erb
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<h1>Make your form here</h1>
<form method="POST" action="/pirates">
<label>Pirate Name:<input type="text" name="pirate[name]"/></label><br>
<label>Pirate Weight:<input type="text" name="pirate[weight]"/></label><br>
<label>Pirate Height:<input type="text" name="pirate[height]"/></label><br>
<h3>First Ship</h3>
<label for="ship_name_1">Ship Name:<input id="ship_name_1" type="text" name="pirate[ships][][name]"/></label><br>
<label for="ship_type_1">Ship Type:<input id="ship_type_1" type="text" name="pirate[ships][][type]"/></label><br>
<label for="ship_booty_1">Ship Booty:<input id="ship_booty_1" type="text" name="pirate[ships][][booty]"/></label><br>
<h3>Second Ship</h3>
<label for="ship_name_2">Ship Name:<input id="ship_name_2" type="text" name="pirate[ships][][name]"/></label><br>
<label for="ship_type_2">Ship Type:<input id="ship_type_2" type="text" name="pirate[ships][][type]"/></label><br>
<label for="ship_booty_2">Ship Booty:<input id="ship_booty_2" type="text" name="pirate[ships][][booty]"/></label><br>
<input type="submit" value="Submit" id="Submit">
</form>
21 changes: 14 additions & 7 deletions views/pirates/show.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<h1>Display your Pirate here</h1>


<h2>Display your first ship here</h2>


<h2>Display your second ship here</h2>
<h1>Pirate Info</h1>
<p>Name: <%= @pirate.name %>
<p>Height: <%= @pirate.height %>
<p>Weight: <%= @pirate.weight %>

<h2>First Ship Info</h2>
<p>Name: <%= @ship1.name %></p>
<p>Type: <%= @ship1.type %></p>
<p>Booty: <%= @ship1.booty %></p>

<h2>Second Ship Info</h2>
<p>Name: <%= @ship2.name %></p>
<p>Type: <%= @ship2.type %></p>
<p>Booty: <%= @ship2.booty %></p>