diff --git a/app.rb b/app.rb index 585554a..9f97c41 100644 --- a/app.rb +++ b/app.rb @@ -2,8 +2,24 @@ module FormsLab class App < Sinatra::Base + get '/' do + erb :root + end - # code other routes/actions here + 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..79009a0 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_reader :name, :weight, :height + + PIRATES = [] + + def initialize(args) + @name = args[:name] + @weight = args[:weight] + @height = args[:height] + PIRATES << self + end + + def self.all + PIRATES + end +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..da23e83 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_reader :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 = [] + end +end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..643c0e9 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,25 @@ -

Make your form here

+
+

Pirate

+
+
+
+
+
+

+ +

Ship(s)

+
+
+
+
+
+

+ +
+
+
+
+
+
+ +
diff --git a/views/pirates/show.erb b/views/pirates/show.erb index f7832d2..dfe13ce 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,16 @@ -

Display your Pirate here

+

Pirates

+
+

Name: <%= @pirate.name %>


+

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


+

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

+

-

Display your first ship here

- - -

Display your second ship here

+

Ships

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

Name: <%= ship.name %>


+

Type: <%= ship.type %>


+

Booty: <%= ship.booty %>

+

+<% end %>