Question

I just started learning Grails and I'm trying to play around with the database using the grails console, but I notice that there's a difference between running grails console and running grails, then console:

When launching grails console straight from Terminal:

~/Desktop/Grails-lab/racetrack $ grails console
| Compiling 1 source files.....

In the console:

groovy> import racetrack.* 
groovy> def z = new User(userName:"bangkuangwang",fullName:"noge noge",website:"noge.com",email:"email@email.com",bio:"hello world",password:"123123") 
groovy> z.save() 
groovy> println(z.errors) 
groovy> User.count 

grails.validation.ValidationErrors: 0 errors

Result: 1

When launching using grails, then console:

~/Desktop/Grails-lab/racetrack $ grails
| Enter a script name to run. Use TAB for completion: 
grails> console
| Compiling 1 source files.....

In the console:

groovy> import racetrack.* 
groovy> def z = new User(userName:"bangkuangwang",fullName:"noge noge",website:"noge.com",email:"email@email.com",bio:"hello world",password:"123123") 
groovy> z.save() 
groovy> println(z.errors) 
groovy> User.count 

Exception thrown

groovy.lang.MissingMethodException: No signature of method: racetrack.User.save() is applicable for argument types: () values: []
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any()
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)
at racetrack.User.save(User.groovy)
at racetrack.User$save.call(Unknown Source)
at ConsoleScript0.run(ConsoleScript0:3)
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1231)
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1231)

Can anyone explain to me why are the 2 methods of launching grails console behave differently?

Was it helpful?

Solution

Looks like a bug. I would recommend you stick to "grails console".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top