RichUI星级评分问题

时间:2011-07-01 23:39:28

标签: grails grails-plugin

1 个答案:

答案 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)
   }
   }