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 @@ +
<%= @pirate.weight %>
+ <%= @pirate.height %>
<%= ship.type %>
+ <%= ship.booty %>