Saturday, April 7, 2012

Create Grails app


  • create-app blog
  • create-domain-class post
  • Edit Post.groovy:
    • package blog
      class Post {
          String title
          String content
          Date date
          static constraints = {    }
      }
  • generate-all blog.Post
  • create-domain-class comment
  • Add comments to Post.groovy:
    • class Post {
          String subject
          String content
          Date date
          static hasMany = [comments: Comment]
          static constraints = {
              // Ordering constraint
              subject()
              content()
              date()
              comments()    }
      }
  • generate-all *
  • add to views/post/show.gsp
    • <g:link class="comment" action="comment" id="${postInstance?.id}"><g:message code="default.button.comment.label" default="Comment" /></g:link>