diff --git a/app.rb b/app.rb index 585554a..40f2914 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,37 @@ require './environment' - +require 'pry' module FormsLab class App < Sinatra::Base - # code other routes/actions here + get '/' do + erb :root + end + + get '/new' do + erb :new + end + + post '/pirates' do + + @pirate = Pirate.new + @pirate.name = params[:pirate][:name] + @pirate.weight = params[:pirate][:weight] + @pirate.height = params[:pirate][:height] + + params[:pirate][:ships].each do |data_hash| + Ship.new(data_hash) + end + @ships = Ship.all + + # # @ship_1.booty = params[:pirate][:ships][][:booty] + # # @ship_2.name = params[:pirate][:ships][][:name] + # # @ship_2.type = params[:pirate][:ships][][:type] + # # @ship_2.booty = params[:pirate][:ships][][:booty] + #use each_with_index on params[:pirate][:ships] and use Ship.All to view the created ships and assign them variables. + + + erb :show + end end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..f3f5206 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,13 @@ class Pirate -end \ No newline at end of file +attr_accessor :name, :weight, :height +@@all = [] + + def initialize + @@all << self + end + + def self.all + @@all + end + +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..404ff0c 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,19 @@ class Ship -end \ No newline at end of file +attr_accessor :name, :type, :booty +@@all = [] + def initialize(args) + @name = args[:name] + @type = args[:type] + @booty = args[:booty] + @@all << self + end + + def self.all + @@all + end + + def self.clear + @@all.clear + end + +end diff --git a/views/.DS_Store b/views/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/views/.DS_Store differ diff --git a/views/new.erb b/views/new.erb new file mode 100644 index 0000000..f88e13b --- /dev/null +++ b/views/new.erb @@ -0,0 +1,24 @@ + + + + + Basketball Team Signup + + +

Make your form here

+
+

Name:

+

Weight:

+

Height:

+ +

Name:

+

Type:

+

Booty:

+ +

Name:

+

Type:

+

Booty:

+ +
+ + diff --git a/views/pirates/new.erb b/views/pirates/new.erb deleted file mode 100644 index f407a19..0000000 --- a/views/pirates/new.erb +++ /dev/null @@ -1 +0,0 @@ -

Make your form here

diff --git a/views/pirates/show.erb b/views/pirates/show.erb deleted file mode 100644 index f7832d2..0000000 --- a/views/pirates/show.erb +++ /dev/null @@ -1,7 +0,0 @@ -

Display your Pirate here

- - -

Display your first ship here

- - -

Display your second ship here

diff --git a/views/show.erb b/views/show.erb new file mode 100644 index 0000000..2acb620 --- /dev/null +++ b/views/show.erb @@ -0,0 +1,25 @@ + + + + + + + +

Display your Pirate here

+

<%= @pirate.name %>

+

<%= @pirate.weight %>

+

<%= @pirate.height %>

+ +

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

+ + +