Skip to content

Instantly share code, notes, and snippets.

@sheehan
Created May 16, 2012 15:25
Show Gist options
  • Save sheehan/2711258 to your computer and use it in GitHub Desktop.
Save sheehan/2711258 to your computer and use it in GitHub Desktop.
<!-- in the head of main.gsp -->
<script>
(function () {
var json = <%= (json ?: []) as JSON %>;
MyApp.config = json;
})();
</script>
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
import grails.util.Environment
import org.grails.plugins.settings.Setting
class JsonFilters {
def securityService
def filters = {
all(controller: '*', action: '*') {
after = { model ->
if (!request.xhr) {
model = model ?: [:]
Map existingJson = model.json ?: [:]
model.json = [
serverURL: ConfigurationHolder.config?.grails?.serverURL,
contextPath: GrailsWebRequest.lookup(request).contextPath,
env: Environment.current.name,
someUrl: grailsApplication.config.someservice.jsonsuggest.url,
userLogin: securityService.userLogin?.mapify(),
params: params
] + existingJson
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment