diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c2788da Binary files /dev/null and b/.DS_Store differ diff --git a/app.rb b/app.rb index 585554a..09e2fae 100644 --- a/app.rb +++ b/app.rb @@ -4,6 +4,22 @@ 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(params[:pirate]) + params[:pirate][:ships].each do |details| + Ship.new(details) + end + @ships = Ship.all + erb :show + # binding.pry + end end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..8d11a46 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..9b14a3a 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..49ef013 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..4c01b7d --- /dev/null +++ b/views/new.erb @@ -0,0 +1,21 @@ +
+ Pirate Name: +
+ Pirate Weight: +
+ Pirate Height: +
+ Ship Name: +
+ Ship Type: +
+ Ship Booty: +
+ Ship Name: +
+ Ship Type: +
+ Ship 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..e2de3b9 --- /dev/null +++ b/views/show.erb @@ -0,0 +1,15 @@ +

Pirate

+ +

Pirate Name: <%=@pirate.name%>

+

Pirate Weight: <%=@pirate.weight%>

+

Pirate Height: <%=@pirate.height%>

+ +

Ships

+ +<%@ships.each do |ship|%> +

Ship Name: <%=ship.name%>

+

Ship Type: <%=ship.type%>

+

Ship Booty: <%=ship.booty%>

+ <%end%> + +