【问题标题】:404 error with scaffolding in GrailsGrails 中的脚手架出现 404 错误
【发布时间】:2013-11-06 01:04:53
【问题描述】:

我试图按照 Grails In Action (http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf) 中的分步说明以及第 1.5.1 节第 1.5.1 页中解释的脚手架。 21-23 似乎不适合我。

我按照建议在QuoteController.groovy 中添加了static scaffold = true。然后 grails run-app,当我前往 localhost:8080/qotd/quote/<b>list</b> 时,我得到一个 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

包 qtd 类报价控制器 { 静态脚手架 = true 定义索引(){ 重定向(动作:“家”) } 默认主页(){ 渲染“真正的程序员不吃乳蛋饼” } 定义随机(){ def allQuotes = Quote.list() def 随机报价 def n = allQuotes.size() 如果 (n > 0){ def randomIdx = new Random().nextInt(n) randomQuote = allQuotes[randomIdx] } 别的{ String str = "真正的程序员不吃乳蛋饼" + n randomQuote = new Quote(作者:“匿名”, 内容:str) } [引用:随机引用] } }

但是,转到localhost:8080/qotd/quote/<b>create</b> 工作正常(与 pdf 中的图 1.12 匹配),我可以创建新报价。

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

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

我是 Groovy 和 Grails 的新手,非常感谢任何帮助。 谢谢!

【问题讨论】:

    标签: grails scaffold


    【解决方案1】:

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

    【讨论】:

    • 非常感谢您的即时反馈(这对像我这样的新手非常有帮助)。我也在 Git 上提出了这个问题,解决方案正是你提到的。这是其他面临相同问题的人的 Git 链接github.com/GrailsInAction/graina2/issues/54
    【解决方案2】:

    现在版本 2.4.2 有更多变化。 以下 url 解释了脚手架是如何移动到插件模型的:

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

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

    所以,在plugins { } 部分内添加这一行:

    compile ":scaffolding:2.0.0"
    

    此外,如果数据库仍然为空,请使用“创建”操作将数据强制输入数据库。 例如:

    localhost:8080/myapp/mycont/create

    然后试试看能不能加载:

    localhost:8080/myapp/mycont/show/1

    替换:

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

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 2011-06-25
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多