We are using grails 2.3.3 for our application.
Access to resources needs to be done with REST interfaces, because it will be accessed from web browser and other applications.
To achieve that, an UrlMapping.groovy contains REST mappings like:
"/toys"(resources:"toy")
The controller is inherited from 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)
}
}
We have a problem with updating items by using g:formRemote with jQuery plugin.
<g:formRemote name="updateForm"
id="${toy.id}"
method="PUT"
url="[controller: 'toy', action:'update' ]">
When updating, it doesn't use proper URL:
Request URL: http://localhost:8080/app/toy/update
METHOD: PUT
FORM DATA: ...
AFAIK the URL should be like:
Request URL: http://localhost:8080/app/toys/5252
METHOD: PUT
FORM DATA: ...
Is this proper way to use g:formRemote with RESTful resources in Grails 2.3?
Shall g:formRemote be able to use URL mapping to create proper URLs?
g:link has attribute resource to generate links to REST resources. Is there an equivalent for forms as well?
<g:link resource="${book}">My Link</g:link>
You can't pass id like that through a formRemote. Same applies for params. You have to add them as part of the url param block, like so.