-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/create_actors.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE actors ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT, | ||
nationality TEXT, | ||
image TEXT --URL for a pic | ||
); | ||
|
||
--sample seed data | ||
|
||
INSERT INTO actors (name, nationality) VALUES ("Tom Holland", "British"); | ||
INSERT INTO actors (name, nationality) VALUES ("Anne Hathaway", "American"); | ||
INSERT INTO actors (name, nationality) VALUES ("Brad Pitt", "American"); |
10 changes: 10 additions & 0 deletions
10
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/create_movies.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE movies ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT, | ||
image TEXT | ||
); | ||
|
||
INSERT INTO movies (name) VALUES ('Spider-Man: Homecoming'); | ||
INSERT INTO movies (name) VALUES ('Alice in Wonderland'); | ||
INSERT INTO movies (name) VALUES ('Mr. & Mrs. Smith'); | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
require 'sinatra' | ||
require 'sinatra/reloader' | ||
require 'sqlite3' | ||
require 'active_record' | ||
|
||
ActiveRecord::Base.establish_connection( | ||
:adapter => 'sqlite3', | ||
:database => 'database.sqlite3' | ||
) | ||
|
||
ActiveRecord::Base.logger = Logger.new(STDERR) | ||
|
||
class Actor < ActiveRecord::Base | ||
end | ||
|
||
class Movie < ActiveRecord::Base | ||
end | ||
|
||
|
||
get '/' do | ||
erb :home | ||
end | ||
|
||
get '/actors' do | ||
@actors = Actor.all | ||
erb :actors_index | ||
end | ||
|
||
#new | ||
get '/actors/new' do | ||
erb :actors_new | ||
end | ||
#create | ||
post '/actors' do | ||
actor = Actor.new | ||
actor.name = params[:name] | ||
actor.nationality = params[:nationality] | ||
actor.image = params[:image] | ||
actor.save | ||
redirect to ('/actors') #get | ||
end | ||
#show | ||
|
||
get '/actors/:id' do | ||
@actor = Actor.find params[:id] | ||
erb :actors_show | ||
end | ||
#edit | ||
get '/actors/:id/edit' do | ||
@actor = Actor.find params[:id] | ||
erb :actors_edit | ||
end | ||
#update | ||
post '/actors/:id' do | ||
actor = Actor.find params[:id] | ||
actor.name = params[:name] | ||
actor.nationality = params[:nationality] | ||
actor.image = params[:image] | ||
actor.save | ||
redirect to ("/actors/#{params[:id]}") | ||
end | ||
|
||
#Delete | ||
get '/actors/:id/delete' do | ||
actor = Actor.find params[:id] | ||
actor.destroy | ||
redirect to ('/actors') | ||
end | ||
|
||
get '/movies' do | ||
@movies = Movie.all | ||
erb :movies_index | ||
end | ||
#NEW | ||
get '/movies/new' do | ||
erb :movies_new | ||
end | ||
|
||
#CREATE | ||
post '/movies' do | ||
movie = Movie.new | ||
movie.name = params[:name] | ||
movie.image = params[:image] | ||
movie.save | ||
redirect to ("/movies/#{ movie.id}") | ||
end | ||
|
||
#SHOW | ||
get '/movies/:id' do | ||
@movie = Movie.find params[:id] | ||
erb :movies_show | ||
end | ||
|
||
#EDIT | ||
get "/movies/:id/edit" do | ||
@movie = Movie.find params[:id] | ||
erb :movies_edit | ||
|
||
end | ||
|
||
#UPDATE | ||
post '/movies/:id' do | ||
movie = Movie.find params[:id] | ||
movie.name = params[:name] | ||
movie.image = params[:image] | ||
movie.save | ||
redirect to ("/movies/#{movie.id}") | ||
end | ||
|
||
#DELETE | ||
get '/movies/:id/delete' do | ||
movie = Movie.find params[:id] | ||
movie.destroy | ||
redirect to ('/movies') | ||
end | ||
|
||
def query_db(sql_statement) | ||
db = SQLite3::Database.new 'database.sqlite3' | ||
db.results_as_hash = true | ||
results = db.execute sql_statement | ||
db.close | ||
results | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/public/css/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
body { | ||
background-color: rgb(160, 201, 231); | ||
|
||
} | ||
.container { | ||
max-width: 1080px; | ||
margin: 0 auto; | ||
background-color: rgb(224, 238, 192); | ||
padding: 30px; | ||
background-image: url ("../public/background.jpg"); | ||
|
||
} | ||
.background { | ||
background-image: url ("background.jpg"); | ||
max-width: 1080px ; | ||
position: relative; | ||
opacity: 60%; | ||
} | ||
nav { | ||
text-align: right; | ||
position: absolute; | ||
} | ||
|
||
.feature { | ||
max-width: 100%; | ||
position: absolute; | ||
padding: 130px | ||
} |
21 changes: 21 additions & 0 deletions
21
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/actors_edit.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>Edit Actor </h1> | ||
|
||
<form action="/actors/<%= @actor["id"]%>" method="post"> | ||
<label> | ||
Name: | ||
<input name="name" placeholder="Johnny Depp" required value="<%= @actor["name"]%>"> | ||
|
||
</label> | ||
|
||
<label> | ||
Nationality: | ||
<input name="nationality" placeholder="American" value="<%= @actor["nationality"]%>"> | ||
</label> | ||
|
||
<label> | ||
Image: | ||
<input type="url" name="image" placeholder="http://..." value="<%= @actor["image"]%>"> | ||
</label> | ||
|
||
<button>Update actor</button> | ||
</form> |
12 changes: 12 additions & 0 deletions
12
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/actors_index.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
<h1>All actors</h1> | ||
|
||
<% @actors.each do |actor| %> | ||
<p> | ||
<a href="/actors/<%= actor["id"] %>"> | ||
<%= actor["name"] %> | ||
</a> | ||
</p> | ||
<% end %> | ||
|
21 changes: 21 additions & 0 deletions
21
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/actors_new.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>New Actor </h1> | ||
|
||
<form action="/actors" method="post"> | ||
<label> | ||
Name: | ||
<input name="name" placeholder="Johnny Depp" required> | ||
|
||
</label> | ||
|
||
<label> | ||
Nationality: | ||
<input name="nationality" placeholder="American"> | ||
</label> | ||
|
||
<label> | ||
Image: | ||
<input type="url" name="image" placeholder="http://..."> | ||
</label> | ||
|
||
<button>Create actors</button> | ||
</form> |
11 changes: 11 additions & 0 deletions
11
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/actors_show.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1><%= @actor["name"] %></h1> | ||
<h2>Nationality: <%= @actor["nationality"]%></h2> | ||
|
||
<% unless @actor["image"].nil?||@actor["image"].empty?%> | ||
<img class="feature" src="<%= @actor["image"] %>" alt="<%= @actor["name"] %>"> | ||
<% end %> | ||
|
||
<div class="controls"> | ||
<a href="/actors/<%= @actor["id"]%>/edit">Edit actor</a> | ||
<a href="/actors/<%= @actor["id"]%>/delete">Delete actors</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1> | ||
Check all the actors and fantastic movies | ||
</h1> | ||
|
||
<p> | ||
Welcome | ||
</p> | ||
|
25 changes: 25 additions & 0 deletions
25
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/layout.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Actors and movies</title> | ||
<link rel="stylesheet" href="/css/style.css"> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<img class= "background" src="background.jpg" alt="background image"> | ||
<nav> | ||
<a href="/actors"> All actors</a> | ||
<a href="/actors/new"> New actor</a> | ||
| | ||
<a href="/movies">All movies</a> | ||
<a href="/movies/new">New movie</a> | ||
</nav> | ||
<%= yield %> | ||
</div> | ||
|
||
</body> | ||
</html> |
16 changes: 16 additions & 0 deletions
16
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/movies_edit.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>Edit movie </h1> | ||
|
||
<form action="/movies/<%= @movie["id"]%>" method="post"> | ||
<label> | ||
Name: | ||
<input name="name" placeholder="The Avengers" required value="<%= @movie["name"]%>"> | ||
|
||
</label> | ||
|
||
<label> | ||
Image: | ||
<input type="url" name="image" placeholder="http://..." value="<%= @movie["image"]%>"> | ||
</label> | ||
|
||
<button>Update movie</button> | ||
</form> |
12 changes: 12 additions & 0 deletions
12
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/movies_index.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
<h1>All movies</h1> | ||
|
||
<% @movies.each do |movie| %> | ||
<p> | ||
<a href="/movies/<%= movie["id"] %>"> | ||
<%= movie["name"] %> | ||
</a> | ||
</p> | ||
<% end %> | ||
|
17 changes: 17 additions & 0 deletions
17
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/movies_new.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h1>New movie </h1> | ||
|
||
<form action="/movies" method="post"> | ||
<label> | ||
Name: | ||
<input name="name" placeholder="The Avengers" required> | ||
|
||
</label> | ||
|
||
|
||
<label> | ||
Image: | ||
<input type="url" name="image" placeholder="http://..."> | ||
</label> | ||
|
||
<button>Create movie</button> | ||
</form> |
11 changes: 11 additions & 0 deletions
11
Sam Yang/wk04 - starts 28th Mar/5-fri/actors/views/movies_show.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1><%= @movie["name"] %></h1> | ||
|
||
|
||
<% unless @movie["image"].nil?||@movie["image"].empty?%> | ||
<img class="feature" src="<%= @movie["image"] %>" alt="<%= @movie["name"] %>"> | ||
<% end %> | ||
|
||
<div class="controls"> | ||
<a href="/movies/<%= @movie["id"]%>/edit">Edit movie</a> | ||
<a href="/movies/<%= @movie["id"]%>/delete">Delete Movies</a> | ||
</div> |