Created
November 5, 2013 14:44
-
-
Save asuraphel/7320074 to your computer and use it in GitHub Desktop.
my Grails controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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