From 12634935fdbd75d477740b718b10b66010f6f8f6 Mon Sep 17 00:00:00 2001 From: Leila Weiss Date: Fri, 3 May 2019 10:06:15 -0400 Subject: [PATCH] Done. --- app.rb | 18 +++++++++++++++++- app/models/pirate.rb | 16 +++++++++++++++- app/models/ship.rb | 21 ++++++++++++++++++++- views/pirates/new.erb | 26 +++++++++++++++++++++++++- views/pirates/show.erb | 18 ++++++++++++++---- 5 files changed, 91 insertions(+), 8 deletions(-) diff --git a/app.rb b/app.rb index 585554a..9f97c41 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..07cacfa 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,16 @@ class Pirate -end \ No newline at end of file + 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 diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..ae2f427 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,21 @@ class Ship -end \ No newline at end of file + 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 + diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..643c0e9 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,25 @@ -

Make your form here

+
+

Pirate

+
+
+
+
+
+

+ +

Ship(s)

+
+
+
+
+
+

+ +
+
+
+
+
+
+ +
diff --git a/views/pirates/show.erb b/views/pirates/show.erb index f7832d2..41a756a 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,17 @@ -

Display your Pirate here

+

Pirates

-

Display your first ship here

+
+

Name: <%= @pirate.name %>


+

Weight: <%= @pirate.weight %> pounds


+

Height: <%= @pirate.height %> inches

+

- -

Display your second ship here

+

Ships

+<% @ships.each do |ship| %> +
+

Name: <%= ship.name %>


+

Type: <%= ship.type %>


+

Booty: <%= ship.booty %>

+

+<% end %>