On Fri, 03 Jul 2009 21:50:38 -0500, Jeff Brown wrote:
> Can you post the source code for StoryControllerTests and Story?
>
Sure:
class StoryController {
def index = { redirect(action:list,params:params) }
// the delete, save and update actions only accept POST requests
static allowedMethods = [delete:'POST', save:'POST', update:'POST']
... some unused actions
def create = {
def storyInstance = new Story()
def subject = SecurityUtils.getSubject()
storyInstance.author = User.findByUsername(subject.getPrinciple())
return ['storyInstance':storyInstance]
}
def save = {
def storyInstance = new Story()
storyInstance.properties = params
if(!storyInstance.hasErrors() && storyInstance.save()) {
flash.message = "Story ${storyInstance.id} created"
redirect(action:show,id:storyInstance.id)
}
else {
render(view:'create',model:[storyInstance:storyInstance])
}
}
}
And the domain class:
class Story {
String title
String description
String text
boolean adult
static belongsTo = [author:User]
static hasMany = [ratings:Rating, categories:Category]
static constraints = {
title(blank:false, nullable:false)
description(blank:false, nullable:false, maxSize:1000)
text(blank:false, nullable:false,
maxSize:Integer.MAX_VALUE)
categories(nullable:false, minSize:1)
}
static mapping = {
columns {
text type :'text'
}
}
}
--
Ken T. <
ktectropy@...>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email