[racket] 2 minor suggestion to the Tutorial "Continue: Web Applications in Racket"

From: J G Cho (gcho at fundingmatters.com)
Date: Sun Apr 15 00:29:43 EDT 2012

1. Currently the following Formlet is used:

(define new-post-formlet
  (formlet
   (#%# ,{input-string . => . title}
        ,{input-string . => . body})
   (values title body)))

Although it is pretty and elegant, some people might benefit seeing
the more verbose version:

(define new-post-formlet
  (formlet
   (#%# (fieldset
         (label ((for "name")) "Title")
         ,((to-string (required (text-input #:attributes '((id
"name")(class "form-text"))))) . => . title))
        (fieldset
         (label ((for "body")) "Body")
         ,((to-string (required (text-input #:attributes '((id
"body")(class "form-text"))))) . => . body)))
   (values title body)))

Possible reason is that if one (who is not very good at CSS) wants to
use/borrow/copy an existing CSS, then it's easier to add class
attributes to tags than modifying CSS. As a Formlet newbie, it took a
bit of head scratching to figure out how to do this.



2. model should show how to use Pooled/Virtual Connection (as detailed
in collects/db).

in model-4.rkt (maybe):

(define (initialize-blog! db)
  (define the-blog (blog db))
  (unless (table-exists? db "posts")

instead of

(define (initialize-blog! home)
  (define db (sqlite3-connect #:database home #:mode 'create))
  (define the-blog (blog db))

plus (virtual-statement "INSERT ... (?,?)") in places of various
prepared statements.

in servlet code:

(require web-server/formlets
           db
           "model-4.rkt")

(define db
  (virtual-connection
   (connection-pool
    (lambda ()
      (sqlite3-connect
       #:database (build-path (current-directory) "the-blog-data.sqlite")
       #:mode 'create)))))

(define (start request)
  (render-blog-page
   (initialize-blog! db)
   request))

instead of:

(require web-server/formlets
         "model-3.rkt")

(define (start request)
  (render-blog-page
   (initialize-blog!
    (build-path (current-directory)
                "the-blog-data.sqlite"))
   request))

as hinted in db documentation.

I really like the db module and as a newbie, I know I would've
appreciated seeing it in the tutorial.


But then again, the tutorial is pretty long already...so maybe not.

jGc

Posted on the users mailing list.