diff --git a/app.rb b/app.rb index 585554a..de567d1 100644 --- a/app.rb +++ b/app.rb @@ -3,7 +3,24 @@ 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 |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..0c768f7 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,15 @@ class Pirate -end \ No newline at end of file + attr_accessor :name, :weight, :height + @@all = [] + + def initialize(params) + @name = params[:name] + @weight = params[:weight] + @height = params[:height] + @@all << self + end + + def self.all + @@all + end +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..748ec1a 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 + @@all = [] + + def initialize(params) + @name = params[:name] + @type = params[:type] + @booty = params[:booty] + @@all << self + end + + def self.all + @@all + end + + def self.clear + @@all.clear + end +end diff --git a/spec/01_sinatra_forms_spec.rb b/spec/01_sinatra_forms_spec.rb index dfd5689..6fd11b7 100644 --- a/spec/01_sinatra_forms_spec.rb +++ b/spec/01_sinatra_forms_spec.rb @@ -75,6 +75,7 @@ end it "returns a 200 status code" do + # binding.pry expect(last_response.status).to eq(200) end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..bd2f97f 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,14 @@
Name: <%= @pirate.name %>
Weight: <%= @pirate.weight %>
Height: <%= @pirate.height %>
Name: <%= @ships.first.name %>
Type: <%= @ships.first.type %>
Booty: <%= @ships.first.booty %>
Name: <%= @ships[1].name %>
Type: <%= @ships[1].type %>
Booty: <%= @ships[1].booty %>