1
votes

I was trying to follow the step-by-step instructions in Grails In Action (http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf), and the scaffolding explained in section 1.5.1, Pg. 21-23 does not seem to be working for me.

I added the static scaffold = true in the QuoteController.groovy as suggested. Then did grails run-app, and when I head to localhost:8080/qotd/quote/list I get a 404 error (instead of the Figure 1.11 in the pdf) as follows:

HTTP Status 404 - /qotd/quote/list
type Status report
message /qotd/quote/list
description The requested resource is not available.
Apache Tomcat/7.0.42

Here is the QuoteController.groovy:

package qotd

class QuoteController {
    static scaffold = true

    def index() { 
        redirect(action: "home")
    }

    def home() {
        render "Real Programmers do not eat Quiche"
    }

    def random() {
        def allQuotes = Quote.list()
        def randomQuote
        def n = allQuotes.size()
        if (n > 0){
            def randomIdx = new Random().nextInt(n)
            randomQuote = allQuotes[randomIdx]
        } else{
            String str = "Real Programmers Don't Eat Quiche" + n
            randomQuote = new Quote(author: "Anonymous",
                    content: str)
        }
        [quote: randomQuote]
    }
}

However, going to localhost:8080/qotd/quote/create works fine (matches with Figure 1.12 in the pdf), and I am able to create a new quote.

The versions I am using are:
App version: 0.1
Grails version: 2.3.1
Groovy version: 2.1.8
JVM version: 1.7.0_45

Is this a bug in Grails or I am missing something?

I am new to Groovy and Grails, and any help would be highly appreciated. Thank you!

2

2 Answers

4
votes

The list action has been removed for some reason. Use index instead.

0
votes

There are more changes now with version 2.4.2. The following url explains how scaffolding has been moved to the plugin model:

http://grails.org/doc/latest/guide/scaffolding.html

"As of Grails 2.3, the scaffolding feature has been moved to a plugin. By default this is configured for installation in new applications, but if you are upgrading from a previous version of Grails you will need to add the following configuration to your BuildConfig.groovy file..."

So, inside the plugins { } section add this line:

compile ":scaffolding:2.0.0"

Also, use the action 'create' to force data into your database if it's still empty. For example:

localhost:8080/myapp/mycont/create

Then try to see if you can load it with:

localhost:8080/myapp/mycont/show/1

Replace:

myapp --> with your application name (used in 'grails create-app')

mycont --> your controller name (used in 'grails create-controller')