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 %>