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..df149bb 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,20 @@ -

Display your Pirate here

+

Pirate

-

Display your first ship here

+

Name: <%= @pirate.name %>

+

Weight: <%= @pirate.weight %>

+

Height: <%= @pirate.height %>

+
+

Ships

+

Head of the Fleet

+

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

+

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

+

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

+ + +

Back up ship in case HoF goes DOWN

+

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

+

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

+

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

-

Display your second ship here