public
anonymous / main.rb
Created

main.rb

  • Download Gist
main.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.