1
我們對我們的應用程序使用grails 2.3.3。g:formRemote不會創建正確的代碼來更新RESTful資源
訪問資源需要使用REST接口完成,因爲它將從Web瀏覽器和其他應用程序訪問。
爲了實現這一目標,一個UrlMapping.groovy包含像REST映射:
"/toys"(resources:"toy")
控制器從ResftulController
import grails.rest.RestfulController
class ToyController extends RestfulController {
// Derived from RestfulController as described in
// http://grails.org/doc/latest/guide/webServices.html#REST
//
// All RAILS functions implemented in base class
static responseFormats = ['json', 'html']
ToyController() {
super(Toy)
}
}
繼承我們有通過自定義g更新項目的一個問題:formRemote與jQuery插件。
<g:formRemote name="updateForm"
id="${toy.id}"
method="PUT"
url="[controller: 'toy', action:'update' ]">
更新時,它不使用正確的網址:
Request URL: http://localhost:8080/app/toy/update
METHOD: PUT
FORM DATA: ...
AFAIK的URL應該是這樣的:
Request URL: http://localhost:8080/app/toys/5252
METHOD: PUT
FORM DATA: ...
就是用克這種正確的方法:formRemote REST風格Grails 2.3中的資源?
g:formRemote能夠使用URL映射來創建正確的URL?
g:鏈接具有屬性資源以生成到REST資源的鏈接。對於表單還有一個等價物嗎?
<g:link resource="${book}">My Link</g:link>