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
680 B

  1. %w[sinatra dm-core dm-migrations haml sass].each{ |lib| require lib }
  2. DataMapper.setup(:default, File.join("sqlite3://",settings.root,"development.db"))
  3. class Robot
  4. include DataMapper::Resource
  5. property :id, Serial
  6. property :top, Integer, default: proc { |m,p| 1+rand(6) }
  7. property :middle, Integer, default: proc { |m,p| 1+rand(4) }
  8. property :bottom, Integer, default: proc { |m,p| 1+rand(5) }
  9. end
  10. DataMapper.finalize
  11. get ('/styles.css'){ scss :styles }
  12. get '/' do
  13. @robots = Robot.all
  14. haml :index
  15. end
  16. post '/build/robot' do
  17. robot = Robot.create
  18. redirect to('/')
  19. end
  20. delete '/delete/robot/:id' do
  21. Robot.get(params[:id]).destroy
  22. redirect to('/')
  23. end