diff --git a/app.rb b/app.rb index 585554a..a39ba0d 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,29 @@ -require './environment' +require_relative 'config/environment' +require 'sinatra/base' +require 'sinatra/reloader' if ENV['RACK_ENV'] != 'production' -module FormsLab - class App < Sinatra::Base +class App < Sinatra::Base + configure :development, :test do + register Sinatra::Reloader if defined?(Sinatra::Reloader) + also_reload '**/*.rb' + end + + get '/' do + erb :root + end + + get '/new' do + erb :"pirates/new" + end + + post '/pirates' do + @pirate = Pirate.new(params[:pirate]) - # code other routes/actions here + params[:pirate][:ships].each do |details| + Ship.new(details) + end + @ships = Ship.all + erb :"pirates/show" end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..b531885 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..79bcc4d 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_reader :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/config.ru b/config.ru index 9ab7d0a..5b106e2 100644 --- a/config.ru +++ b/config.ru @@ -1,2 +1,2 @@ require './app' -run FormsLab::App \ No newline at end of file +run App diff --git a/environment.rb b/config/environment.rb similarity index 78% rename from environment.rb rename to config/environment.rb index a1ccf5e..d469012 100644 --- a/environment.rb +++ b/config/environment.rb @@ -1,4 +1,4 @@ -ENV['SINATRA_ENV'] ||= "development" +ENV['SINATRA_ENV'] ||= 'development' require 'bundler' Bundler.require(:default, ENV['SINATRA_ENV']) diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..ca17bdb 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,43 @@
<%= @pirate.name %>
+<%= @pirate.weight %>
-<%= @pirate.height %>
+<%= ship1.name %>
+<%= ship1.type %>
+<%= ship1.booty %>
+<% end %><%= ship2.name %>
+<%= ship2.type %>
+<%= ship2.booty %>
+<% end %>