Skip to content

Instantly share code, notes, and snippets.

@irfani
Created January 17, 2011 18:27
Show Gist options
  • Save irfani/783204 to your computer and use it in GitHub Desktop.
Save irfani/783204 to your computer and use it in GitHub Desktop.
simple todolist app
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'haml'
class Todo
include DataMapper::Resource
property :id, Serial
property :text, String
end
configure do
DataMapper.setup(:default, "sqlite:///development.sqlite3")
DataMapper.auto_migrate!
end
get '/' do
@todos = Todo.all
haml :index
end
post '/' do
Todo.create(:text => params['todo'])
redirect '/'
end
__END__
@@ index
!!!
%html
%head
%title Todo
%body
%h1 Todo
%ul
- @todos.each do |todo|
%li= todo.text
%form{:action => '/', :method => 'POST'}
%input{:type => 'text', :name => 'todo'}
%input{:type => 'submit', :value=> 'Todo!'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment