From d2861cce65a83418a7d6381ad9aae84aaf18d190 Mon Sep 17 00:00:00 2001 From: Cayla Horsey Date: Thu, 8 Aug 2024 10:46:37 -0400 Subject: [PATCH] Complete all tests --- app.rb | 25 +++++++++++++++++++++++- app/models/pirate.rb | 16 ++++++++++++++- app/models/ship.rb | 20 ++++++++++++++++++- views/pirates/new.erb | 44 ++++++++++++++++++++++++++++++++++++++++++ views/pirates/show.erb | 18 +++++++++++++---- 5 files changed, 116 insertions(+), 7 deletions(-) diff --git a/app.rb b/app.rb index 585554a..a646710 100644 --- a/app.rb +++ b/app.rb @@ -3,7 +3,30 @@ module FormsLab class App < Sinatra::Base - # code other routes/actions here + get '/' do + erb :root + end + + get '/new' do + erb :'pirates/new' + end + + get 'pirates' do + erb :'pirates/show' + 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..fd1e49d 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_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 diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..b04e4a2 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,20 @@ class Ship -end \ No newline at end of file + attr_accessor :name, :type, :booty + + SHIPS = [] + + def initialize(params) + @name = params[:name] + @type = params[:type] + @booty = params[:booty] + SHIPS << self + end + + def self.all + SHIPS + end + + def self.clear + SHIPS.clear + end +end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..b9850f8 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,45 @@

Make your form here

+
+

Pirate

+
+ + +

+ + + +

+ + + +

+ +

First Ship

+
+ + +

+ + + +

+ + + +

+ +

Second Ship

+ + +

+ + + +

+ + + +

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

Display your Pirate here

+

Pirate

+
+

Pirate Name: <%= @pirate.name %>


+

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


+

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


+

-

Display your first ship here

- - -

Display your second ship here

+

Display your ships here

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

Name: <%= ship.name %>


+

Type: <%= ship.type %>


+

Booty: <%= ship.booty %>


+

+<% end %>