Skip to content

Commit

Permalink
Rails skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
petergcutler committed Jul 28, 2015
1 parent 85fbd9a commit 1ec0388
Show file tree
Hide file tree
Showing 70 changed files with 1,325 additions and 3 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@ Your app should have the following RESTful actions:

1. Write 5 user stories for your app.
* Keep it simple and think about what functionality your MVP needs.

* As a user, I want to be able to upload pictures to share with friends
* As a user, I want to be able to remove pictures I have uploaded, to save myself from embarassment
* As a user, I want to be able to see multiple author's pictures so I can keep up with
others
* As a user I want to be able to edit/update pictures I have uploaded to modify my original submissions
* As a user I want to be able to write a caption with photos, to share funny comments.

2. Create a database: `$ createdb wdinstagram`
3. Create an Entry model

4. Create a `wdinstagram_schema.sql` schema file and generate a table for your Entry model.
* When ready, migrate your schema into PSQL: `$ psql -d wdinstagram < db/wdinstagram_schema.sql`
* When ready, migrate your schema into PSQL: `$ psql -d wdinstagram < db/schema.sql`


5. Create seed data in `$ db/seeds.rb`
* When ready, run your seeds file: `$ ruby db/seeds.rb`


6. Create routes for your app, mapping them to the RESTful actions listed above

7. Create the views for your routes

### Bonus
Expand Down
42 changes: 42 additions & 0 deletions controllers/entries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
get '/' do
@entries = Entry.all
erb :index
end

get '/new' do
erb :new
end

get '/:id' do
@entry = Entry.find(params[:id])
erb :show
end

post '/' do
@entry = Entry.create(params[:entry])
redirect "/#{@entry.id}"
# Same as redirect "/artists/" + @artist.id.to_s
end

get '/:id/edit' do
@entry = Entry.find(params[:id])
erb :edit
end

put "/:id" do
@entry = Entry.find(params[:id])
@entry.update(params[:entry])
redirect "/#{@entry.id}"
end

delete '/:id' do
@entry = Entry.find(params[:id])
@entry.destroy
redirect "/"
end

get '/:author' do
@author = Entry.find_by(author:"")
@entries = Entry.find(params[:author])
erb :author
end
7 changes: 7 additions & 0 deletions db/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
:adapter => "postgresql",
:database => "wdinstagram"
)

if defined?(Sinatra)
# Fix an issue with sinatra and Active Record where connections are left open
after do
ActiveRecord::Base.connection.close
end
end
9 changes: 9 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS entries;

CREATE TABLE entries (
id SERIAL PRIMARY KEY,
author TEXT,
photo_url TEXT,
date_taken TEXT,
caption TEXT
);
23 changes: 21 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
require 'bundler/setup'
require "pry"
require 'active_record'
require 'pry'

require_relative "../db/connection"
require_relative "connection"
require_relative "../models/entry"

Entry.destroy_all

eich = Entry.create(
author: "Brendan Eich",
photo_url: "http://cnet4.cbsistatic.com/hub/i/r/2012/02/26/24cf0440-f0e6-11e2-8c7c-d4ae52e62bcc/resize/370xauto/434f5240b3a3752f41c966b9987f723d/20120226_Brendan_Eich_001.jpg",
date_taken: "March, 2013",
caption: "Sunny")
matz = Entry.create(
author: "Yukihiro Matsumoto",
photo_url: "http://i.ytimg.com/vi/IGG4l_QEzog/maxresdefault.jpg",
date_taken: "April, 2013",
caption: "Woah")
rossum = Entry.create(
author: "Guido van Rossum",
photo_url: "https://upload.wikimedia.org/wikipedia/commons/6/66/Guido_van_Rossum_OSCON_2006.jpg",
date_taken: "March, 2013",
caption: "Beer")
2 changes: 2 additions & 0 deletions models/entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Entry < ActiveRecord::Base
end
93 changes: 93 additions & 0 deletions public/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -----------------------------------*/
/* --- RESETS ---*/
/* -----------------------------------*/

/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

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;
}

/* -----------------------------------*/
/* --- BORDER BOX ---*/
/* -----------------------------------*/

/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}

/* -----------------------------------*/
/* --- GLOBAL ---*/
/* -----------------------------------*/


body, ul {
background-color: #ecf0f1;
font-family: 'Arimo', serif;
font-size: 1.2em;
display: flex;
flex-direction: column;
align-items: center;
}

li {
margin: .2em;
}

a {
text-decoration: none;
color: #e67e22;
}

img {
border: 1px dashed #e67e22;
padding: 5px;
width: 10em;
}
24 changes: 24 additions & 0 deletions views/author.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Author's Posts
<a href="/new">(+)</a>
</h1>

<ul>
<% @entries.each do |entry| %>
<li>
<a href='/<%= entry.id %>'><%= entry.author %></a>
</li>

<li>
<%= entry.date_taken %>
</li>

<li>
<img src='<%= entry.photo_url %>'>
</li>

<li>
<%= entry.caption %>
</li>

<% end %>
</ul>
10 changes: 10 additions & 0 deletions views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h3>Editing Entry</h3>

<form action="/<%= @entry.id %>" method="post">
<input type="hidden" name="_method" value="put"> <!-- for REST -->
<input value="<%= @entry.author %>" name="entry[author]" placeholder="Author's Name" type="text">
<input value="<%= @entry.photo_url %>" name="entry[photo_url]" placeholder="Photo URL" type="text">
<input value="<%= @entry.date_taken %>" name="entry[date_taken]" placeholder="Date Taken" type="text">
<input value="<%= @entry.caption %>" name="entry[caption]" placeholder="caption" type="text">
<input type="submit" value="Update">
</form>
25 changes: 25 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ul>
<li>
<h1>Entries
<a href="/new">(+)</a>
</h1>
</li>
<% @entries.each do |entry| %>
<li>
<a href='/<%= entry.author %>'><%= entry.author %></a>
</li>

<li>
<%= entry.date_taken %>
</li>

<li>
<a href='/<%= entry.id %>'><img src='<%= entry.photo_url %>'></a>
</li>

<li>
<%= entry.caption %>
</li>

<% end %>
</ul>
14 changes: 14 additions & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<link href='http://fonts.googleapis.com/css?family=Arimo:400,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="/styles.css">
</head>

<body>
<%= yield %>
</body>

</html>
9 changes: 9 additions & 0 deletions views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h3>Creating New Entry</h3>

<form method="post" action="/">
<input name="entry[author]" placeholder="Author's Name" type="text">
<input name="entry[photo_url]" placeholder="Photo URL" type="text">
<input name="entry[date_taken]" placeholder="date_taken" type="text">
<input name="entry[caption]" placeholder="caption" type="text">
<input type="submit">
</form>
19 changes: 19 additions & 0 deletions views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<ul>
<li>
<h2><%= @entry.author %></h2>
</li>

<li>
<img src='<%= @entry.photo_url %>'>
</li>

<li>
<a href="/<%= @entry.id %>/edit">Edit Entry</a>
</li>

<li>
<form method="post" action="/<%= @entry.id %>">
<input name="_method" value="delete" type="hidden">
<input type="submit" value="Delete Entry">
</form>
</li>
13 changes: 13 additions & 0 deletions wdinstagram/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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 all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
45 changes: 45 additions & 0 deletions wdinstagram/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use postgresql as the database for Active Record
gem 'pg'
# 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'

# 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

0 comments on commit 1ec0388

Please sign in to comment.