Created
February 6, 2010 09:06
-
-
Save anotherjesse/296622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'activity.rb' | |
| run Activity::App |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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