store.rb 935 B

123456789101112131415161718192021222324252627282930313233
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. class StoreApp
  10. def call(env)
  11. x = Builder::XmlMarkup.new :indent=>2
  12. x.declare! :DOCTYPE, :html
  13. x.html do
  14. x.head do
  15. x.title 'Pragmatic Bookshelf'
  16. end
  17. x.body do
  18. x.h1 'Pragmatic Bookshelf'
  19. Product.all.each do |product|
  20. x.h2 product.title
  21. x << " #{product.description}\n"
  22. x.p product.price
  23. end
  24. end
  25. end
  26. response = Rack::Response.new(x.target!)
  27. response['Content-Type'] = 'text/html'
  28. response.finish
  29. end
  30. end