作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为Grails开发带有RichUI插件的评分系统。首先,我有以下代码:
class RatingController {
def springSecurityService
static scaffold = true
def rate = {
def rating = params.rating
def artist = Artist.get( params.id )
def currentUser = currentUser()
currentUser.addToRatings(new Rating(artist:artist, rating:rating)).save()
render(template: "/artist/rate", model: [artist: artist, rating: rating])
}
private currentUser(){
return User.get(springSecurityService.principal.id)
}
}
class RatingController {
def springSecurityService
static scaffold = true
def rate = {
def rating = params.rating
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)
}
}
最佳答案
我才发现问题出在哪里。我必须将等级的输入值转换为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)
}
}
关于grails - RichUI星级评定存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554168/
我是一名优秀的程序员,十分优秀!