Is that return necessary? Let's say it's in the middle of an action.
render(contentType:'text/json', text: ['success': true] as JSON)
return
Description. A multi-purpose method for rendering responses to the client which is best illustrated with a few examples! Warning - this method does not always support multiple parameters. For example, if you specify both collection and model, the model parameter will be ignored.
Using the respond method to output JSON The respond method provides content negotiation strategies to intelligently produce an appropriate response for the given client. For example given the following controller and action: grails-app/controllers/example/BookController.groovy.
If you don't return, any code after render
will also be executed, which is often not what you want, e.g.
def someAction = {
if (someCondition) {
render view: 'success'
// if we don't return execution would fall through to the code below
return
}
log.error 'something went wrong'
render view: 'error'
}
Of course, if you use this style instead, there's no need to return
def someAction = {
if (someCondition) {
render view: 'success'
} else {
log.error 'something went wrong'
render view: 'error'
}
}
If an action only has one exit point, there's no need to return after render
def someAction = {
render view: 'success'
}
Just remember that the code after render
will be executed if you don't return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With