First of all, we have already a form which is prepared in previous part. Now we just set save action for this form and save method contain following code
def save(Contact contact) { if (contact == null) { transactionStatus.setRollbackOnly() notFound() return } if (contact.hasErrors()) { transactionStatus.setRollbackOnly() respond contact.errors, view:'create' return } contact.save flush:true request.withFormat { form multipartForm { flash.message = message(code: 'default.created.message', args: [message(code: 'contact.label', default: 'Contact'), contact.id]) redirect contact } '*' { respond contact, [status: CREATED] } } }
Done