Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created February 6, 2010 09:06
Show Gist options
  • Select an option

  • Save anotherjesse/296622 to your computer and use it in GitHub Desktop.

Select an option

Save anotherjesse/296622 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'dm-core'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3://my.db')
module Activity
class Dogs
include DataMapper::Resource
property :id, Serial
property :name, String
property :description, Text
property :created_at, DateTime
end
class App < Sinatra::Default
set :run, false
get '/' do
'<a href="/new">new dog</a><br><ul>' + (Activity::Dogs.all.collect { |d| "<li><a href='/dog/#{d.id}'>#{d.name}</a>" }).join("\n")
end
get '/dog/:id' do
dog = Activity::Dogs[params[:id]]
"<h1>Dog #{dog.id} is #{dog.name}</h1><p>#{dog.description}</p>"
end
get '/new' do
"<form method='post'><input type='text' name='name'><br><textarea name='description'>"
end
post '/new' do
Activity::Dogs.create :name => params[:name], :description => params[:description]
redirect '/'
end
end
end
require 'activity.rb'
run Activity::App
0) download this source
1) create a heroku project
2) git push heroku master
3) heroku console
4) DataMapper.auto_migrate!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment