Created
January 17, 2011 18:27
-
-
Save irfani/783204 to your computer and use it in GitHub Desktop.
simple todolist 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
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