答案 0 :(得分:2)
我刚刚发现了问题所在。我不得不将评级的输入值转换为double类型。因此,以下代码按原样运行:
class RatingController {
def springSecurityService
static scaffold = true
def rate = {
def rating = params.rating.toDouble()
def artist = Artist.get( params.id )
def currentUser = currentUser()
if(! currentUser.ratings.artist.contains(artist)){
currentUser.addToRatings(new Rating(artist:artist, rating:rating)).save()
render(template: "/artist/rate", model: [artist: artist, rating: rating])
}
else{
currentUser.ratings.find{it.artist==artist}.rating = rating
currentUser.save()
render(template: "/artist/rate", model: [artist: artist, rating: rating])
}
}
private currentUser(){
return User.get(springSecurityService.principal.id)
}
}