Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done: #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
module FormsLab
class App < Sinatra::Base

# code other routes/actions here
get '/' do
erb :root
end

get '/new' do
erb :'pirates/new'
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
15 changes: 14 additions & 1 deletion app/models/pirate.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
class Pirate
end
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
20 changes: 19 additions & 1 deletion app/models/ship.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@

class Ship
end
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

def self.clear
@@all.clear
end
end
1 change: 1 addition & 0 deletions spec/01_sinatra_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
end

it "returns a 200 status code" do
# binding.pry
expect(last_response.status).to eq(200)
end

Expand Down
13 changes: 13 additions & 0 deletions views/pirates/new.erb
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<h1>Make your form here</h1>

<form action="/pirates" method="post">
<p>Pirate Name: <input type="text" name="pirate[name]"></p>
<p>Pirate Weight: <input type="text" name="pirate[weight]"></p>
<p>Pirate Height: <input type="text" name="pirate[height]"></p>
<p>Ship Name: <input id="ship_name_1" type="text" name="pirate[ships][][name]"></p>
<p>Ship Type: <input id="ship_type_1" type="text" name="pirate[ships][][type]"></p>
<p>Ship Booty: <input id="ship_booty_1" type="text" name="pirate[ships][][booty]"></p>
<p>Ship Name: <input id="ship_name_2" type="text" name="pirate[ships][][name]"></p>
<p>Ship Type: <input id="ship_type_2" type="text" name="pirate[ships][][type]"></p>
<p>Ship Booty: <input id="ship_booty_2" type="text" name="pirate[ships][][booty]"></p>
<button type="submit">Submit</button>
</form>
11 changes: 9 additions & 2 deletions views/pirates/show.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<h1>Display your Pirate here</h1>

<p>Name: <%= @pirate.name %></p><br>
<p>Weight: <%= @pirate.weight %></p><br>
<p>Height: <%= @pirate.height %></p><br>

<h2>Display your first ship here</h2>

<p>Name: <%= @ships.first.name %></p><br>
<p>Type: <%= @ships.first.type %></p><br>
<p>Booty: <%= @ships.first.booty %></p><br>

<h2>Display your second ship here</h2>
<p>Name: <%= @ships[1].name %></p><br>
<p>Type: <%= @ships[1].type %></p><br>
<p>Booty: <%= @ships[1].booty %></p><br>