From fea1d144405dae5b169171db0703edf9d8ad923c Mon Sep 17 00:00:00 2001 From: KFad Date: Fri, 3 May 2019 09:32:43 -0400 Subject: [PATCH 1/2] Fun with Pirate Forms, Arrr --- app.rb | 19 ++++++++++++++++++- app/models/pirate.rb | 17 ++++++++++++++++- app/models/ship.rb | 21 ++++++++++++++++++++- views/pirates/new.erb | 14 +++++++++++++- views/pirates/show.erb | 15 ++++++++++++++- 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/app.rb b/app.rb index 585554a..8e0eb8f 100644 --- a/app.rb +++ b/app.rb @@ -3,7 +3,24 @@ 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 |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..9075ba1 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,17 @@ 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..93f06ab 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_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..a8084fa 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,13 @@ -

Make your form here

+ +
+

Pirate Name:

+

Pirate Weight:

+

Pirate Height:

+

Ship Name:

+

Ship Type:

+

Ship Booty:

+

Ship Name:

+

Ship Type:

+

Ship Booty:

+ +
diff --git a/views/pirates/show.erb b/views/pirates/show.erb index f7832d2..0f06f4e 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,20 @@ -

Display your Pirate here

+

Pirate

+

Name: <%= @pirate.name %>


+

Weight: <%= @pirate.weight %>

+

Height: <%= @pirate.height %>

+
+ +

Ships

Display your first ship here

+

<%= @ships[0].name%>

+

<%= @ships[0].type%>

+

<%= @ships[0].booty%>

Display your second ship here

+

<%= @ships[1].name%>

+

<%= @ships[1].type%>

+

<%= @ships[1].booty%>

+ From f6f034cee077f69a7c59993bcd0cedad478fcfe5 Mon Sep 17 00:00:00 2001 From: KFad Date: Fri, 3 May 2019 09:35:55 -0400 Subject: [PATCH 2/2] Clean formating up on show.erb --- views/pirates/show.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/views/pirates/show.erb b/views/pirates/show.erb index 0f06f4e..df149bb 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,19 +1,19 @@

Pirate

-

Name: <%= @pirate.name %>


+

Name: <%= @pirate.name %>

Weight: <%= @pirate.weight %>

Height: <%= @pirate.height %>


Ships

-

Display your first ship here

+

Head of the Fleet

<%= @ships[0].name%>

<%= @ships[0].type%>

<%= @ships[0].booty%>

-

Display your second ship here

+

Back up ship in case HoF goes DOWN

<%= @ships[1].name%>

<%= @ships[1].type%>

<%= @ships[1].booty%>