From 577f3e2b05d71a787b4690f70563fc1a05d7531c Mon Sep 17 00:00:00 2001 From: gillianwenhold Date: Tue, 9 Jul 2019 21:52:51 -0400 Subject: [PATCH] Done. --- app.rb | 17 ++++++++++++++++- app/models/pirate.rb | 16 +++++++++++++++- app/models/ship.rb | 20 +++++++++++++++++++- views/pirates/new.erb | 15 ++++++++++++++- views/pirates/show.erb | 21 ++++++++++++++------- 5 files changed, 78 insertions(+), 11 deletions(-) diff --git a/app.rb b/app.rb index 585554a..ac9e0c7 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..b531885 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..03ce480 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(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 diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..be288e8 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,14 @@ -

Make your form here

+
+
+
+
+

First Ship

+
+
+
+

Second Ship

+
+
+
+ +
diff --git a/views/pirates/show.erb b/views/pirates/show.erb index f7832d2..26dd47f 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,14 @@ -

Display your Pirate here

- - -

Display your first ship here

- - -

Display your second ship here

+

Pirate Info

+

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

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

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

First Ship Info

+

Name: <%= @ship1.name %>

+

Type: <%= @ship1.type %>

+

Booty: <%= @ship1.booty %>

+ +

Second Ship Info

+

Name: <%= @ship2.name %>

+

Type: <%= @ship2.type %>

+

Booty: <%= @ship2.booty %>