Sitepoint demo app for learning to use Sinatra
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

29 lines
519 B

13 years ago
  1. require 'sinatra'
  2. require 'data_mapper'
  3. require 'haml'
  4. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
  5. class Task
  6. include DataMapper::Resource
  7. property :id, Serial
  8. property :name, String, required: true
  9. property :completed_at, DateTime
  10. end
  11. DataMapper.finalize
  12. get '/' do
  13. @tasks = Task.all
  14. haml :index
  15. end
  16. post '/' do
  17. Task.create name: params[:task]
  18. redirect '/'
  19. end
  20. get '/:task' do
  21. @task = params[:task].split('-').join(' ').capitalize
  22. haml :task
  23. end