This is great, but usually you would want to provide some kind of feedback to the user as to what has happened:
def delete = {
def b = Book.get( params.id )
b.delete()
render "Book ${b.id} was deleted"
}
GSP code:
<div id="message"></div>
<g:remoteLink action="delete" id="1" update="message">Delete Book</g:remoteLink>
The above example will call the action and set the contents of the
message
div
to the response in this case
"Book 1 was deleted"
. This is done by the
update
attribute on the tag, which can also take a map to indicate what should be updated on failure:
<div id="message"></div>
<div id="error"></div>
<g:remoteLink action="delete" id="1"
update="[success:'message',failure:'error']">Delete Book</g:remoteLink>
Here the
error
div will be updated if the request failed.