Skip to content

Instantly share code, notes, and snippets.

@andyhawthorne
andyhawthorne / view_post.erb
Created October 17, 2012 20:38
Sinatra view post
<h3><%[email protected] %></h3>
<p><em><%= @post.created_at.strftime("%e %b %Y %H:%m:%S%p") %></em></p>
<%[email protected] %>
@andyhawthorne
andyhawthorne / posts.erb
Created October 17, 2012 20:35
Sinatra posts
<h2>Posts</h2>
<% unless @posts.empty? %>
<% @posts.each do |post| %>
<p>
<a href="/view/<%= post.id %>"><%= post.title %></a> -
<em><%= post.created_at.strftime("%e %b %Y %H:%m:%S%p") %></em>
</p>
<% end %>
<% else %>
<p>No posts available at the moment.</p>
@andyhawthorne
andyhawthorne / main.rb
Created October 17, 2012 20:32
Sinatra model
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :content, Text
property :created_at, DateTime
end
DataMapper.finalize
@andyhawthorne
andyhawthorne / about.erb
Created October 17, 2012 20:29
Sinatra layout
get '/about' do
erb: about
end
@andyhawthorne
andyhawthorne / layout.erb
Created October 17, 2012 20:22
Sinatra layout
<div id="sidebar-wrapper">
<div id="sidebar">
<%= erb :'partials/twitter' %>
</div>
</div>
@andyhawthorne
andyhawthorne / layout.erb
Created October 17, 2012 20:20
Sinatra layout
<div id="content-wrapper">
<div id="content">
<%= yield %>
</div>
</div>
@andyhawthorne
andyhawthorne / main.rb
Created October 17, 2012 20:18
home method
get '/' do
erb :index
end
@andyhawthorne
andyhawthorne / main.rb
Created October 17, 2012 20:15
sinatra db
#database connection
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
@andyhawthorne
andyhawthorne / main.rb
Created October 17, 2012 20:13
Sinatra1
require 'sinatra'
require 'data_mapper'
require 'dm-migrations'
require 'dm-timestamps'
<?php
class Testing_example extends CI_Driver
{
private $CI;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->database();
}