Created
May 16, 2012 15:25
-
-
Save sheehan/2711258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- in the head of main.gsp --> | |
<script> | |
(function () { | |
var json = <%= (json ?: []) as JSON %>; | |
MyApp.config = json; | |
})(); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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