Skip to content

anonymous /main.rb

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
main.rb
require 'sinatra'
require 'data_mapper'
require 'slim'
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
class Task
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :completed_at, DateTime
end
###Task.auto_upgrade!
DataMapper.finalize
get '/' do
@tasks = Task.all
slim :index
end
get '/:task' do
@task = params[:task].split('-').join(' ').capitalize
slim :task
end
post '/' do
Task.create params[:task]
redirect to('/')
end
delete '/task/:id' do
Task.get(params[:id]).destroy
redirect to('/')
end
put '/task/:id' do
task = Task.get params[:id]
task.completed_at = task.completed_at.nil? ? Time.now : nil
task.save
redirect to('/')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.