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 @@ + + +
+ +<%= @pirate.name %>
+<%= @pirate.weight %>
+<%= @pirate.height %>
+ +<%= @ships[0].name%>
+<%= @ships[0].type%>
+<%= @ships[0].booty%>
+ + +<%= @ships[1].name%>
+<%= @ships[1].type%>
+<%= @ships[1].booty%>
+ + +