Skip to content

Instantly share code, notes, and snippets.

@innovationfactory
Created May 8, 2009 14:49
Show Gist options
  • Save innovationfactory/108806 to your computer and use it in GitHub Desktop.
Save innovationfactory/108806 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'datamapper'
DataMapper.setup(:default, 'sqlite3::memory:')
class Idea
include DataMapper::Resource
property :id, Serial
property :body, Text
end
DataMapper.auto_migrate!
get '/' do
"<p>" +
Idea.count.to_s +
Idea.all.inject(""){|sum, idea| sum << "#{idea.body} <br/>" } +
"</p>" +
'<form action="/" method="POST">
<textarea name="idea" id="idea" rows="20"></textarea>
<br/><input type="submit" value="Submit"/>
</form>'
end
post '/' do
idea = Idea.new
idea.body = params["idea"]
idea.save
redirect '/'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment