Skip to content

Instantly share code, notes, and snippets.

@asuraphel
Created November 5, 2013 14:44
Show Gist options
  • Save asuraphel/7320074 to your computer and use it in GitHub Desktop.
Save asuraphel/7320074 to your computer and use it in GitHub Desktop.
my Grails controller
package qotd
class QuoteController {
def index() {
redirect( action: "home" )
}
def home() {
render "<h1>My first grails app.</h1>"
}
def random() {
def allQuotes = Quote.list()
def randomQuote
if( allQuotes.size() > 0) {
def randomIdx = new Random().nextInt( allQuotes.size())
randomQuote = allQuotes[randomIdx]
}
else {
randomQuote = new Quote( author: "Lao Tzu", content: "What has no substance passes through what has no openings.")
}
[quote: randomQuote, size: allQuotes.size()]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment