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

Final submission #78

Open
wants to merge 4 commits 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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Gemfile.lock
tmp/
coverage
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ group :development, :test do
gem 'rspec'
gem 'shotgun'
gem 'tux'
gem 'simplecov'
end
21 changes: 21 additions & 0 deletions app/controllers/laugh_tracks_app.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
class LaughTracksApp < Sinatra::Base
set :public_folder, File.dirname(__FILE__) + '../public'

get '/comedians' do
if params[:age]
@comedians = Comedian.where(age: params[:age])
else
@comedians = Comedian.all
end
@specials = Special.all
erb :"comedians/index"
end

get '/comedians/new' do
erb :"comedians/new"
end

post '/comedians' do
comedian = Comedian.new(params[:comedian])
comedian.save
redirect '/comedians'
end
end
9 changes: 9 additions & 0 deletions app/models/comedian.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Comedian < ActiveRecord::Base
has_many :specials
validates_presence_of :name,
:age,
:birthplace,
:image_url

def self.average_age
average(:age).round
end
end
93 changes: 93 additions & 0 deletions app/models/special.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class Special < ActiveRecord::Base
belongs_to :comedians
validates_presence_of :name,
:runtime_mins,
:comedian_id,
:image_url

def self.average_special_length
average(:runtime_mins).round
end
end

# body {
# background-color: blue;
# }
#
# header {
# background: rgb(60, 60, 60);
# height: 250px;
# border-radius: 10%;
# }
#
# #h1 {
# display: table;
# font-family: 'Fira Sans', sans-serif;
# font-size: 20px;
# padding: 25px;
# margin: auto;
# color: white;
# }
#
# #stat_1{
# display: inline-block;
# width: 22%;
# height: 200px;
# margin: 1em;
# font-family: 'Fira Sans', sans-serif;
# color: white;
# }
#
# #stat_2 {
# display:inline-block;
# width: 22%;
# height: 200px;
# margin: 1em;
# font-family: 'Fira Sans', sans-serif;
# color: white;
# }
# #stat_3 {
# display:inline-block;
# width: 22%;
# height: 200px;
# margin: 1em;
# font-family: 'Fira Sans', sans-serif;
# color: white;
# }
# #stat_4 {
# display: inline-block;
# width: 22%;
# height: 200px;
# margin: 1em;
# font-family: 'Fira Sans', sans-serif;
# color: white
# }
#
# img {
# border-radius: 20%;
# display: block;
# margin-left: auto;
# margin-right: auto;
# width: 20%;
# }
#
# #h1 {
# display: table;
# font-family: 'Fira Sans', sans-serif;
# font-size: 18px;
# padding: 25px;
# margin: auto;
# color: white;
# }
#
# /* main {
# display: flex;
# flex-direction: row;
# } */
# /* #info {
# display: inline-block;
# }
#
# #s_info {
# display: inline-block;
# } */
43 changes: 43 additions & 0 deletions app/public/stylesheets/reset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
74 changes: 74 additions & 0 deletions app/public/stylesheets/start.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
body {
background-color: orange;
}

header {
background: rgb(60, 60, 60);
height: 250px;
border-radius: 10%;
}

#h1 {
display: table;
font-family: 'Fira Sans', sans-serif;
font-size: 20px;
padding: 25px;
margin: auto;
color: white;
}

#stat_1{
display: inline-block;
width: 22%;
height: 200px;
margin: 1em;
font-family: 'Fira Sans', sans-serif;
color: white;
}

#stat_2 {
display:inline-block;
width: 22%;
height: 200px;
margin: 1em;
font-family: 'Fira Sans', sans-serif;
color: white;
}
#stat_3 {
display:inline-block;
width: 22%;
height: 200px;
margin: 1em;
font-family: 'Fira Sans', sans-serif;
color: white;
}
#stat_4 {
display: inline-block;
width: 22%;
height: 200px;
margin: 1em;
font-family: 'Fira Sans', sans-serif;
color: white
}

img {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}

#h1 {
display: table;
font-family: 'Fira Sans', sans-serif;
font-size: 18px;
padding: 25px;
margin: auto;
color: white;
}

li {
font-size: 18px;
list-style-type: none;
}
68 changes: 68 additions & 0 deletions app/views/comedians/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

<html>
<head>
<title>Comedians</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="/stylesheets/start.css">
</head>
<body>
<header>
<h1 id="h1">Comedian Info</h1>
<nav>
<div id="stat_1">
Average Comedian Age: <%= @comedians.average(:age).round %> years old
</div>
<% @sum = 0 %>
<% @comedians.each do |comedian| %>
<% comedian.specials.sum do |special| %>
<% @sum += special.runtime_mins %>
<% @sum %>
<% end %>
<% end %>
<% @num = 0 %>
<% @comedians.each do |comedian| %>
<% @num += comedian.specials.count %>
<% end %>
<% if @num == 0 %>
<% @average = 0 %>
<% else %>
<% @average = @sum / @num %>
<% end %>
<div id="stat_2">
Average TV Special Run Length: <%= @average %> mins
</div>
<div id="stat_3">
Birth Cities:
<% @comedians.each do |comedian| %>
<%= comedian.birthplace %>
<% end %>
</div>
<div id="stat_4">
Special Count:
<% @comedians.each do |comedian| %>
<%= comedian.name %>:
<%= comedian.specials.count %>
<% end %>
</div>
</nav>
</header>
<main>
<% @comedians.each do |comedian| %>
<div id="comedian-<%=comedian.id%>">
<li id="name"><%= comedian.name %></li>
<li id="age">Age: <%= comedian.age %></li>
<li id="birthplace">Birthplace: <%= comedian.birthplace %></li>
<img id="image" src=<%= comedian.image_url %>></img>
</div>
<% comedian.specials.each do |special| %>
<div id="special-<%=special.id%>">
<li id="special">Special Count: <%= comedian.specials.count %></li>
<li>Specials:</li>
<li> <%= special.name %></li>
<li id="s_run"> Length: <%= special.runtime_mins %></li>
<img src=<%= special.image_url %></img>
<% end %>
<% end %>
</div>
</body>
</hmtl>
12 changes: 12 additions & 0 deletions app/views/comedians/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<form action="/comedians" method="post">
<p>Enter info for a new Comedian:</p>
Name:<br>
<input type='text' name='comedian[name]'/><br/>
Age:<br>
<input type='text' name='comedian[age]'/><br/>
Birthplace:<br>
<input type='text' name='comedian[birthplace]'/><br/>
Image url:<br>
<input type='text' name='comedian[image_url]'/><br/>
<input type='submit'/>
</form>
10 changes: 10 additions & 0 deletions db/migrate/20190314191008_create_comedians.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateComedians < ActiveRecord::Migration[5.2]
def change
create_table :comedians do |t|
t.text :name
t.integer :age
t.text :birthplace
t.text :image_url
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20190314201107_create_specials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateSpecials < ActiveRecord::Migration[5.2]
def change
create_table :specials do |t|
t.text :name
t.integer :runtime_mins
t.integer :comedian_id
t.text :image_url
end
end
end
16 changes: 15 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 2019_03_14_201107) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "comedians", force: :cascade do |t|
t.text "name"
t.integer "age"
t.text "birthplace"
t.text "image_url"
end

create_table "specials", force: :cascade do |t|
t.text "name"
t.integer "runtime_mins"
t.integer "comedian_id"
t.text "image_url"
end

end
Loading