Grails中脚手架404错误

时间:2013-10-27 05:02:05

标签: grails scaffold

我试图遵循Grails In Action(http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf)中的逐步说明,以及第1.5.1节Pg中所述的脚手架。 21-23对我来说似乎不起作用。

我按照建议在static scaffold = true添加了QuoteController.groovy。然后 grails run-app ,当我前往localhost:8080/qotd/quote/list时,我得到404错误(而不是pdf中的图1.11),如下所示:

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

以下是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]
    }
}

但是,转到localhost:8080/qotd/quote/create工作正常(与pdf中的图1.12匹配),我可以创建一个新的引用。

我使用的版本是
应用版本: 0.1
Grails版本: 2.3.1
Groovy版本: 2.1.8
JVM版本: 1.7.0_45

这是Grails中的错误还是我遗漏了什么?

我是Groovy和Grails的新手,任何帮助都将受到高度赞赏。 谢谢!

2 个答案:

答案 0 :(得分:4)

由于某种原因,列表操作已被删除。改为使用索引。

答案 1 :(得分:0)

版本2.4.2现在有更多更改。 以下URL解释了如何将脚手架移动到插件模型:

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

"从Grails 2.3开始,脚手架功能已移至插件中。默认情况下,它配置为在新应用程序中安装,但如果要从以前版本的Grails升级,则需要将以下配置添加到BuildConfig.groovy文件中..."

因此,在plugins { }部分内添加以下行:

compile ":scaffolding:2.0.0"

另外,使用动作'创建'如果数据仍为空,则强制将数据导入数据库。 例如:

<强>本地主机:8080 / MyApp的/ mycont /创建

然后尝试查看是否可以加载:

<强>本地主机:8080 / MyApp的/ mycont /显示/ 1

替换:

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

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