I am a beginner in Grails 2.0 framework and I am trying to follow this tutorial http://grails.org/Simple+Avatar+Uploader . I implemented this code but I am getting an error in UserController.groovy at this line ‘def user = User.current(session)’ as ‘ No such property: User for class: grailtwitter.PersonController’ I assume that this line takes the user’s current session. I am looking for an explanation of how this works ?
Share
This code is incomplete. The controller presupposes that you have a way of identifying the currently logged in user. Implicitly the line
def user = User.current(session)assumes that you have defined acurrent()method on the user class itself that takes in a session and presumably uses some field that you’ve set in it to retrieve a User. That would be kind of dumb.A common way to do this would be to build your own authentication mechanism. Note that this is a naive practice and you are far better off using Spring Security Core unless you want to leave your application open for gaping security holes. But, for practice, something like:
You could then replace the offending line in the tutorial (–
def user = User.current(session)–) withBefore you go much further, you probably want to walk through this free eBook on Grails before you get much further. Also highly recommend Grails in Action.