diff --git a/app.rb b/app.rb index 585554a..e1f505e 100644 --- a/app.rb +++ b/app.rb @@ -4,6 +4,29 @@ module FormsLab class App < Sinatra::Base # code other routes/actions here + get '/' do + erb :index + end + + get '/new' do + erb :'pirates/new' + end + + post '/pirates' do + @pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height]) + + params[:pirate][:ships].each do |ship| + Ship.new(ship[:name], ship[:type], ship[:booty]) + end + + @ships = Ship.all + + erb :'pirates/show' + end + + get '/pirates' do + erb :'pirates/show' + end end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..2d601ef 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,18 @@ class Pirate -end \ No newline at end of file + + attr_accessor :name, :weight, :height + + @@all = [] + + def initialize(name, weight, height) + @name = name + @weight = weight + @height = height + @@all << self + end + + def self.all + @@all + end + +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..31191c8 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,22 @@ class Ship -end \ No newline at end of file + + attr_accessor :name, :type, :booty + + @@all = [] + + def initialize(name, type, booty) + @name = name + @type = type + @booty = booty + @@all << self + end + + def self.all + @@all + end + + def self.clear + @@all.clear + end + +end diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..fc013ee --- /dev/null +++ b/views/index.erb @@ -0,0 +1,2 @@ +

Welcome to the Nested Forms Lab!

+

let's navigate to the '/new'

diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..5e51d3a 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,14 @@ -

Make your form here

+

New Pirate and Ship Listings

+ +
+

Pirate Name:
+ Pirate Weight:
+ Pirate Height:

+

Ship 1 Name:
+ Ship 1 Type:
+ Ship 1 Booty:

+

Ship 2 Name:
+ Ship 2 Type:
+ Ship 2 Booty:

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

Display your Pirate here

- - -

Display your first ship here

- - -

Display your second ship here

+

Pirate:

+

<%= @pirate.name %>

+

<%= @pirate.weight %>
+ <%= @pirate.height %>

+
+

Ships:

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

<%= ship.name %>

+

<%= ship.type %>
+ <%= ship.booty %>

+<% end %>