2010-02-24 17 views
2

我使用腳手架兩個域類幾個控制器的:1扇區到N項:Grails的腳手架鏈路參考問題

class Item { 

String name 

static belongsTo = [sector:Sector] 

.... 

} 

class Sector { 

String name 

static hasMany = [items:Item] 

.... 

} 

當我產生的相應腳手架控制器我使用的模式(類) mgr:Sectormgr.groovy和Itemmgr.groovy。

問題是某些鏈接在某些生成的視圖中無效,因爲它假定我遵循控制器的默認名稱。例如:

  • 如果我去/ sectormgr /顯示/ 20,與它相關聯的項目列表中有鏈接/項目/顯示/ 22,而不是/ itemmgr /顯示/ 22

這有一個簡單的解決辦法嗎?我在創建控制器時錯過了什麼嗎?

在此先感謝

回答

0

有幾種方法來解決我相信。最簡單的就是要堅持Grails的命名你的控制器SectorController.groovy,ItemController.groovy等的約定

另一種方式來處理這一點,我認爲工作是更新您的grails-app/conf目錄/ UrlMappings.groovy。這是默認的腳手架:

class UrlMappings { 
    static mappings = { 
     "/$controller/$action?/$id?"{ 
      constraints { 
       //apply constraints here 
      } 
     } 
     "/"(view:"/index") 
     "500"(view:'/error') 
    } 
} 

你想要的東西,如:

class UrlMappings { 
    static mappings = { 
     "/${controller}mgr/$action?/$id?"{ //Add mgr after controller 
      constraints { 
       //apply constraints here 
      } 
     } 
     "/"(view:"/index") 
     "500"(view:'/error') 
    } 
} 
+0

我很想知道這是否適合你。請告訴我! – 2010-03-02 13:06:47

0

更改URLMappings似乎沒有工作對我來說,這是一個更加全球性的變化。運行intall-templates並更改指向src/templates/scaffolding/show.gsp中控制器的鏈接是我採用的方法。

更改模板後需要重新啓動服務器。