Skip to content
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 Peter_Fagan/week_04/day_04/database.db
Binary file not shown.
8 changes: 8 additions & 0 deletions Peter_Fagan/week_04/day_04/games.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE games (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
genre TEXT,
description TEXT,
cover TEXT,
screenshot TEXT
);
75 changes: 75 additions & 0 deletions Peter_Fagan/week_04/day_04/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require "pry"
require "sinatra"
require "sinatra/reloader"
require "sqlite3"

get "/" do
erb :home
end

get "/pry" do
binding.pry
"Pry route"
end

get "/games" do
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
@all_games = db.execute "SELECT * FROM games;"
db.close
erb :games_index
end

get "/games/new" do
erb :games_new
end

post "/games" do
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
sql = "INSERT INTO games (name, genre, description, cover, screenshot) VALUES ('#{params[:name]}', '#{params[:genre]}', '#{params[:description]}', '#{params[:cover]}', '#{params[:screenshot]}');"
game = db.execute(sql)
db.close
redirect "/games"
end

get "/games/:id/edit" do
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
@game = db.execute( "SELECT * FROM games WHERE id == #{params[:id]};" ).first
db.close
erb :games_edit
end

post "/games/:id" do
sql = "UPDATE games SET name = '#{params[:name]}', genre = '#{params[:genre]}', description = '#{params[:description]}', cover = '#{params[:cover]}', screenshot = '#{params[:screenshot]}' WHERE id == #{params[:id]};"
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
db.execute sql
db.close
redirect "/games/#{params[:id]}"
end

get "/games/:id/delete" do
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
db.execute "DELETE FROM games WHERE id == #{params[:id]};"
db.close
redirect "/games"
end

get "/games/:id" do
db = SQLite3::Database.new("database.db")
db.results_as_hash = true
@game = db.execute( "SELECT * FROM games WHERE id == #{params[:id]};" ).first
db.close
erb :games_show
end

# /games GET index
# /games POST create
# /games/:id GET show
# /games/:id POST update
# /games/:id/new GET new
# /games/:id/edit GET edit
# /games/:id/delete GET delete
13 changes: 13 additions & 0 deletions Peter_Fagan/week_04/day_04/public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
font-family: monospace;
backgorund gainsboro;
}

a{
color: darkblue;
}

.container {
border: 10px solid black;
padding: 20px;
}
25 changes: 25 additions & 0 deletions Peter_Fagan/week_04/day_04/views/games_edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h2>Edit a game on the list</h2>

<form action="/games/<%= @game["id"] %>" method = "POST">
<p>
<label>Game: </label>
<input type="text" name="name" value="<%= @game["name"] %>">
</p>
<p>
<label>Genre: </label>
<input type="text" name="genre" value="<%= @game["genre"] %>">
</p>
<p>
<label>Description: </label>
<input type="text" name="description" value="<%= @game["description"] %>">
</p>
<p>
<label>cover </label>
<input type="text" name="cover" value="<%= @game["cover"] %>">
</p>
<p>
<label>screenshot </label>
<input type="text" name="screenshot" value="<%= @game["screenshot"] %>">
</p>
<input type="submit" value="edit game">
</form>
15 changes: 15 additions & 0 deletions Peter_Fagan/week_04/day_04/views/games_index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2>List of all games</h2>

<% @all_games.each do |game| %>
<ul>
<li>
   <a href="/games/<%= game["id"] %>">ID of <%= game["id"] %></a>
   </li>
<li><strong>Game: </strong><%= game["name"] %></li>
<li><strong>Genre: </strong><%= game["genre"] %></li>
<li><strong>Description: </strong><%= game["description"] %></li>
<li><strong>Cover </strong><%= game["cover"] %></li>
<li><strong>screenshot </strong><%= game["screenshot"] %></li>
</ul>

<% end %>
25 changes: 25 additions & 0 deletions Peter_Fagan/week_04/day_04/views/games_new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h2>Add a new game to the list</h2>

<form action="/games" method = "POST">
<p>
<label>Game: </label>
<input type="text" name="name">
</p>
<p>
<label>Genre: </label>
<input type="text" name="genre">
</p>
<p>
<label>Description: </label>
<input type="text" name="description">
</p>
<p>
<label>cover </label>
<input type="text" name="cover">
</p>
<p>
<label>screenshot </label>
<input type="text" name="screenshot">
</p>
<input type="submit" value="Add game">
</form>
12 changes: 12 additions & 0 deletions Peter_Fagan/week_04/day_04/views/games_show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2>Game ID: <%= @game["id"] %></h2>

<h3><%= @game["name"] %></h3>
<h3><%= @game["genre"] %></h3>
<h3><%= @game["description"] %></h3>

<h3>Cover</h3>
<img src="<%= @game['cover'] %>">
<img src="<%= @game['screenshot'] %>">

<a href="/games/<%= @game['id'] %>/edit">Edit this game</a>
<a href="/games/<%= @game['id'] %>/delete">Delete this game</a>
Empty file.
23 changes: 23 additions & 0 deletions Peter_Fagan/week_04/day_04/views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Games</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>

<nav>
<a href="/">Home</a>
<a href="/games">All Games</a>
<a href="/games/new">Create a game page</a>
</nav>

<h1>My Games page</h1>

<div class = "container">
<%= yield %>
</div>

</body>
</html>
17 changes: 17 additions & 0 deletions Peter_Fagan/week_05/day_01/games_on_rails/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
47 changes: 47 additions & 0 deletions Peter_Fagan/week_05/day_01/games_on_rails/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

Loading