Como usar um g:link para a action update no form?
12/11/2014 11:38
<div class="well well-sm">
<row>
<a href="#">
<i class="ace-icon fa fa-plus-circle purple light-blue bigger-150"></i>
Novo
</a>
<a href="#">
|
</a>
<g:link action="update">
<i class="ace-icon glyphicon glyphicon-share green"></i>
Alterar
</g:link>
<a href="#">
|
</a>
<g:link action="index">
<i class="ace-icon glyphicon glyphicon-list green"></i>
Listar
</g:link>
</row>
</div>
HTTP Status 405 -
type Status report
message
description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/7.0.53
package geo
import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional
@Transactional(readOnly = true)
class CidadeController {
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
def index(Integer max) {
session.menu000 = "[Menu000]"
session.menu001 = "[Menu001]"
session.menu002 = "Cidade"
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[cidadeInstanceList: Cidade.list(max:params.int('max'),offset: 0), cidadeInstanceTotal:Cidade.count()]
}
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[cidadeInstanceList: Cidade.list(max:params.int('max'),offset: 0), cidadeInstanceTotal:Cidade.count()]
}
def lister = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
render(template: 'list', model: [cidadeInstanceList: Cidade.list(params), cidadeInstanceTotal:Cidade.count()])
}
def show(Cidade cidadeInstance) {
respond cidadeInstance
}
def create() {
respond new Cidade(params)
}
@Transactional
def save(Cidade cidadeInstance) {
if (cidadeInstance == null) {
notFound()
return
}
if (cidadeInstance.hasErrors()) {
respond cidadeInstance.errors, view:'create'
return
}
cidadeInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'cidade.label', default: 'Cidade'), cidadeInstance.id])
redirect cidadeInstance
}
'*' { respond cidadeInstance, [status: CREATED] }
}
}
def edit(Cidade cidadeInstance) {
respond cidadeInstance
}
@Transactional
def update(Cidade cidadeInstance) {
if (cidadeInstance == null) {
notFound()
return
}
if (cidadeInstance.hasErrors()) {
respond cidadeInstance.errors, view:'edit'
return
}
cidadeInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.updated.message', args: [message(code: 'Cidade.label', default: 'Cidade'), cidadeInstance.id])
redirect cidadeInstance
}
'*'{ respond cidadeInstance, [status: OK] }
}
}
@Transactional
def delete(Cidade cidadeInstance) {
if (cidadeInstance == null) {
notFound()
return
}
cidadeInstance.delete flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'Cidade.label', default: 'Cidade'), cidadeInstance.id])
redirect action:"index", method:"GET"
}
'*'{ render status: NO_CONTENT }
}
}
protected void notFound() {
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'cidade.label', default: 'Cidade'), params.id])
redirect action: "index", method: "GET"
}
'*'{ render status: NOT_FOUND }
}
}
}
Para se registrar, clique aqui.