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

finished lab #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ module FormsLab
class App < Sinatra::Base

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

get "/new" do
erb :new
end

post "/pirates" do
@pirate = Pirate.new(params[:pirate])
params[:pirate][:ships].each do |details|
Ship.new(details)
end
@ships = Ship.all
erb :show
# binding.pry
end
end
end
15 changes: 14 additions & 1 deletion app/models/pirate.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
class Pirate
end
attr_accessor :name, :weight, :height
@@all = []

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

def self.all
@@all
end
end
19 changes: 18 additions & 1 deletion app/models/ship.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
class Ship
end
attr_accessor :name, :type, :booty
@@all = []

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

def self.all
@@all
end

def self.clear
all.clear
end
end
Binary file added views/.DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<form action="/pirates" method="post">
Pirate Name: <input type="text" name="pirate[name]">
<br>
Pirate Weight: <input type="text" name="pirate[weight]">
<br>
Pirate Height: <input type="text" name="pirate[height]">
<br>
Ship Name: <input id="ship_name_1" type="text" name="pirate[ships][][name]">
<br>
Ship Type: <input id="ship_type_1" type="text" name="pirate[ships][][type]">
<br>
Ship Booty: <input id="ship_booty_1" type="text" name="pirate[ships][][booty]">
<br>
Ship Name: <input id="ship_name_2"type="text" name="pirate[ships][][name]">
<br>
Ship Type: <input id="ship_type_2" type="text" name="pirate[ships][][type]">
<br>
Ship Booty: <input id="ship_booty_2" type="text" name="pirate[ships][][booty]">
<input type="submit" value="Submit">
</form>

1 change: 0 additions & 1 deletion views/pirates/new.erb

This file was deleted.

7 changes: 0 additions & 7 deletions views/pirates/show.erb

This file was deleted.

15 changes: 15 additions & 0 deletions views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1>Pirate</h1>

<h3>Pirate Name: <%[email protected]%></h3>
<h3>Pirate Weight: <%[email protected]%></h3>
<h3>Pirate Height: <%[email protected]%></h3>

<h2>Ships</h2>

<%@ships.each do |ship|%>
<p>Ship Name: <%=ship.name%></p>
<p>Ship Type: <%=ship.type%></p>
<p>Ship Booty: <%=ship.booty%></p>
<%end%>