2013-10-27 39 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')