diff --git a/app.rb b/app.rb index 585554a..a646710 100644 --- a/app.rb +++ b/app.rb @@ -3,7 +3,30 @@ module FormsLab class App < Sinatra::Base - # code other routes/actions here + get '/' do + erb :root + end + + get '/new' do + erb :'pirates/new' + end + + get 'pirates' do + erb :'pirates/show' + 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..fd1e49d 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_accessor :name, :weight, :height + + PIRATES = [] + + def initialize(params) + @name = params[:name] + @weight = params[:weight] + @height = params[:height] + PIRATES << self + end + + def self.all + PIRATES + end +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..b04e4a2 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 + + SHIPS = [] + + def initialize(params) + @name = params[:name] + @type = params[:type] + @booty = params[:booty] + SHIPS << self + end + + def self.all + SHIPS + end + + def self.clear + SHIPS.clear + end +end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..b9850f8 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,45 @@
Name: <%= ship.name %>
Type: <%= ship.type %>
Booty: <%= ship.booty %>