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

Issues with getting persistence project on Heroku #3

Open
wants to merge 3 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
95 changes: 95 additions & 0 deletions #stylesheet.css#
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
*{
font-family: Garamond;
color: black;
}
body{
background-color: #EEEEEE;

}
div {
background-color:white;
border-radius: 5px;
border-style: solid;

}


#header {
display: inline-block;
border-color: #0000ff;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}

#post {
display: inline-block;
border-color: #CC00CC;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}


#name{
display: inline-block;
height: 50px;
width: 300px;
margin: 0px 30px 10px 30px;
text-align: center;
}








#box_title{
display: inline-block;
height: 50px;
width: 300px;
margin: 0px 30px 10px 30px;
text-align: center;
}

#box{
/*display: inline-block;*/
float: left;
height: 300px;
width: 350px;
box-shadow: 10px 10px 5px #888888;
background-color: black;

margin: 20px 30px 20px 30px;



}

tr:nth-child(3) td div{
/*display: inline-block;*/
height: 100px;


/*background-color: black;*/
margin: 20px 30px 10px 30px;
padding: 5px;
}


table{
margin: auto;
width: 100%;
margin-top: 50px;
}

3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'https://rubygems.org'

gem 'rubocop'
gem 'sinatra'
gem 'data_mapper'
26 changes: 9 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
parser (2.2.0.pre.5)
ast (>= 1.1, < 3.0)
slop (~> 3.4, >= 3.4.5)
powerpack (0.0.9)
rainbow (2.0.0)
rubocop (0.26.1)
astrolabe (~> 1.3)
parser (>= 2.2.0.pre.4, < 3.0)
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.6.0)
slop (3.6.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)

PLATFORMS
ruby

DEPENDENCIES
rubocop
sinatra
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec ruby blog.rb -p $PORT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this command working for you locally? I'm getting cannot load such file -- dm-sqlite-adapter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...which means what?

17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# Persistence assignment

Create a site in Sinatra that saves information from a form to a database, then displays that information on the page. Examples:
This is a blog which is editable online. To add a blog entry, type the title and content in a field provided, then click on the submit button.

* A single-user Twitter clone
* A blog that can be edited online
* A note-taking app
* A recipe site
* *etc.*

Using a SQL database is recommended, specifically PostgreSQL (a.k.a. "Postgres") via the [pg](https://bitbucket.org/ged/ruby-pg/wiki/Home) gem. The app doesn't need a lot of bells & whistles, e.g. user authentication, unless you get that first part done early.

**Deploy the application to Heroku**, and **submit a pull request** to this repository. Include:

* All the necessary files
* In the README:
* Setup instructions
* A link to the live app on Heroku
To edit an entry, click on the ID number of the entry.
Binary file added blog.db
Binary file not shown.
47 changes: 47 additions & 0 deletions blog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'sinatra'
require 'data_mapper'

DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/blog.db")

class Post
include DataMapper::Resource
property :id, Serial
property :post_title, Text, required: true
property :content, Text, required: true
property :created_at, DateTime
property :updated_at, DateTime
end

DataMapper.auto_upgrade!

get '/' do
@posts = Post.all order: :id.desc
erb :home
end

post '/' do
p = Post.new
p.post_title = params[:post_title]
p.content = params[:content]
p.created_at = Time.now
p.updated_at = Time.now
p.save
redirect '/'
end

get '/:id/' do
# retreive post from database
@post = Post.get params[:id]
@title = 'Edit blog post'
erb :edit
end

put '/:id' do

p = Post.get params[:id]
p.post_title = params[:post_title]
p.content = params[:content]
p.updated_at = Time.now
p.save
redirect '/'
end
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './blog.rb'
run Sinatra::Application
Binary file added public/Snapshot_20080828_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions public/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
*{
font-family: Arial, Helvetica, Sans-Serif;
color: #151B54;
/*font-size:medium;*/
}
body{
background-color: #EEEEEE;

}
div {
background-color:white;
border-radius: 5px;
border-style: solid;

}


#header {
display: inline-block;
border-color: #0000ff;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}



#post_left {
display: float: left;
border-color: #CC00CC;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}

#post_right {
display: float: left;
/*display: inline-block;*/
border-color: #CC00CC;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}


#new_post {
/*display: inline-block;*/
border-color: orange;
width: 95%;
/*height: 60px;*/

margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}


#name{
display: inline-block;
height: 50px;
width: 300px;
margin: 0px 30px 10px 30px;
text-align: center;
}



#image{
height="100"
width="120"
border-style: 1px solid #DDD;
border-radius: 50%
}




#box_title{
display: inline-block;
height: 50px;
width: 300px;
margin: 0px 30px 10px 30px;
text-align: center;
}

#box{
/*display: inline-block;*/
float: left;
height: 300px;
width: 350px;
box-shadow: 10px 10px 5px #888888;
background-color: black;

margin: 20px 30px 20px 30px;

}

#post_title{
height:20px;
width: 50%;
}

#post_content{
height:100px;
width: 95%;
}


18 changes: 18 additions & 0 deletions views/#layout.erb#
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf8">
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title>Danielle--Blog</title>
</head>
<body>
<!--change from div?-->

<div id="header"><h1>Danielle Zoe Aloicius</h1><br>
<img src="/Snapshot_20080828_1.jpg" alt="DZA" height="100" width="120">
</div>


<%= yield %>
</body>
</html>
10 changes: 10 additions & 0 deletions views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% if @post %>
<form action="/<%= @post.id %>" method="post" id="edit">
<input type="hidden" name="_method" value="put">
<textarea id="post_title" name="post_title" ><%= @post.post_title %></textarea>
<textarea id="post_content" name="content" ><%= @post.content %></textarea>

<input type="submit">
</form>
<% end %>

26 changes: 26 additions & 0 deletions views/home.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div id="new_post">
<form action="/" method="post">
<textarea id="post_title" name="post_title" placeholder="Add Post Title" ></textarea>
<textarea id="post_content" name="content" placeholder="Add Post Contents"></textarea>
<input type="submit" value="Add Post">
</form>
</div>

<% @posts.each_with_index do |post, i| %>

<div <%='id="post_left"' if i % 2==0%>
<%='id="post_right"'if i % 2==1%>


<p class="links">
<a href="/<%= post.id %>/"><%=post.id %></a>
</p>
<%= post.post_title %><br>
<%= post.content %>

<p class="meta">Created: <%= post.created_at %></p>

</div>


<% end %>
Loading