2013-10-27 40 views
1

我试图按照Grails In Action(http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf)中的分步说明进行操作,并在第1.5.1节中解释脚手架。 21-23似乎不适合我。我建议在QuoteController.groovy中加上static scaffold = true。那时 Grails的运行程序,当我前往localhost:8080/qotd/quote/list我得到一个404错误(而不是图1.11中的PDF格式),如下所示:在Grails中使用脚手架时出现404错误

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的新手,任何帮助将不胜感激。 谢谢!

回答

4

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

+0

非常感谢你为眼前的FE edback(对于像我这样的新手来说真的很有帮助)。我也曾在Git上提过这个问题,解决方案就是你刚才提到的。以下是面向相同问题的其他人的Git链接https://github.com/GrailsInAction/graina2/issues/54 – tikka

0

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

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')