diff --git a/app.rb b/app.rb index 585554a..8ca0ad2 100644 --- a/app.rb +++ b/app.rb @@ -4,6 +4,27 @@ 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 + +# extracts the form data from the params and uses it to create a new instance of your model class, something along the lines of Model.create(some_attribute: params[:some_attribute]) + post '/pirates' do + @pirate = Pirate.new(params[:pirate]) + params[:pirate][:ships].each { |ship| Ship.new(ship) } + @ships = Ship.all + + erb :'pirates/show' + end + end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..f2a4119 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 + + @@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..f069d27 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,16 @@ 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 +end diff --git a/spec/01_sinatra_forms_spec.rb b/spec/01_sinatra_forms_spec.rb index dfd5689..22fc4d3 100644 --- a/spec/01_sinatra_forms_spec.rb +++ b/spec/01_sinatra_forms_spec.rb @@ -71,7 +71,7 @@ end after do - Ship.clear + Ship.all.clear end it "returns a 200 status code" do diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..311453b 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,55 @@ -