I’m newbie to groovy.
How can we call domain methods from controller in Grails.
Controller :
def results = User.fetch_results
User Domain :
def fetch_results {
def users = this.get(1)
}
Sorry if the above code is wrong, i need to know how to access domain methods from controller.
thanks.
My code is like this
UserController:
def results = User.addUser
User domain:
def addUser {
def user = new User()
user.id = 1
user.publication_name = pub_name
user.publication_desc = ""
user.edit_date = new Date()
user.save()
}
}
I tried with above code but getting errors . how can we call “addUser” method from controller ?
thanks.
You need to make the method a static method.
Then make sure to import the User object in your controller.