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

Still having some difficulties trying to use Postgres #5

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 Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'https://rubygems.org'

gem 'sinatra'
gem 'rubocop'
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec ruby recall.rb -p $PORT
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './recall.rb'
run Sinatra::Application
31 changes: 31 additions & 0 deletions public/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*{
font-family: Times, Arial;
color: #000000;
}

#new_recipe {
width: 95%;
margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}

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

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

#test{
border: thin solid #000000;
width: 95%;
margin-bottom: 10px;
padding-left: 40px;
padding-top: 10px;
padding-botton: 10px;
}
Binary file added recall.db
Binary file not shown.
33 changes: 33 additions & 0 deletions recall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rubygems'
require 'sinatra'
require 'data_mapper'

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

class Note
include DataMapper::Resource
property :id, Serial
property :content, Text, :required => true
property :content2, Text, :required => true
property :complete, Boolean, :required => true, :default => false
property :created_at, DateTime
property :updated_at, DateTime
end

DataMapper.finalize.auto_upgrade!

get '/' do
@notes = Note.all :order => :id.desc
@title = 'All Notes'
erb :home
end

post '/' do
n = Note.new
n.content = params[:content]
n.content2 = params[:content2]
n.created_at = Time.now
n.updated_at = Time.now
n.save
redirect '/'
end
10 changes: 10 additions & 0 deletions views/delete.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% if @note %>
<p>Are you sure you want to delete the following note: <em>"<%= @note.content %>"</em>?</p>
<form action="/<%= @note.id %>" method="post">
<input type="hidden" name="_method" value="delete">
<input type="submit" value="Yes, Delete It!">
<a href="/<%= @note.id %>">Cancel</a>
</form>
<% else %>
<p>Note not found.</p>
<% end %>
24 changes: 24 additions & 0 deletions views/home.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div id = "new_recipe">
<form action="/" method="post">
<textarea id="fcontent" name="content" placeholder="Recipe name..."></textarea>
<textarea id="scontent" name="content2" placeholder="Ingredients..."></textarea>
<input type="submit" value="Add Recipe!">
</form>
</div>

<% @notes.each do |note| %>
<div id="test">
<p class="links">
<a href="/<%= note.id %>/"<%=note.id %></a>
</p>

<%= note.content %><br>
<%= note.content2 %>

<!-- <p>
<span><a href="/<%= note.id %>">[delete]</a></span>
</p> -->

<p class="meta">Created: <%= note.created_at %></p>
</div>
<% end %>
15 changes: 15 additions & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>

<html lang="en">
<head>
<meta charset="utf8">
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<h1> <center> Cooking Recipes </center> </h1>
</head>

<body>
<div id="main">
<%= yield %>
</div>
</body>
</html>