You can execute code depending on environment you are in following ways:
In Bootstrap:
import grails.util.Environment
class BootStrap {
def init = { servletContext ->
if (Environment.current == Environment.DEVELOPMENT) {
// insert Development environment specific code here
} else
if (Environment.current == Environment.TEST) {
// insert Test environment specific code here
} else
if (Environment.current == Environment.PRODUCTION) {
// insert Production environment specific code here
}
}
}
In Controller:
import grails.util.Environment
class SomeController {
def someAction() {
if (Environment.current == Environment.DEVELOPMENT) {
// insert Development environment specific code here
} else
if (Environment.current == Environment.TEST) {
// insert Test environment specific code here
} else
if (Environment.current == Environment.PRODUCTION) {
// insert Production environment specific code here
}
render “Environment is ${Environment.current}”
}
}
In Views:
<g:if env=”development”>
We are in Development Mode
</g:if>
<g:if env=”production”>
We are in Production Mode
</g:if>
<g:if env=”test”>
We are in Test Mode
</g:if>
ProsperaSoft offers Grails development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Grails experts and consultants.