Rateable Grails Plugin
Groovy CSS Shell JavaScript
Latest commit 176e038 Jan 2, 2017 @graemerocher graemerocher committed on GitHub Merge pull request #2 from gokhanakgul/master
Upgrade to grails 3.2 & gradle 3.0
Permalink
Failed to load latest commit information.
gradle/wrapper Upgrade to grails 3.2 & gradle 3.0 Oct 2, 2016
grails-app fix rating widget Jun 26, 2015
src Upgrade to grails 3.2 & gradle 3.0 Oct 2, 2016
.gitignore Upgrade to Grails 3.0 Jun 26, 2015
.travis.yml Upgrade to Grails 3.0 Jun 26, 2015
LICENSE more efficient and accurate listOrderByAverageRating method (takes nu… Nov 16, 2009
README.md Update README.md Jun 26, 2015
build.gradle Upgrade to grails 3.2 & gradle 3.0 Oct 2, 2016
gradle.properties Upgrade to grails 3.2 & gradle 3.0 Oct 2, 2016
gradlew
gradlew.bat Upgrade to Grails 3.0 Jun 26, 2015
travis-build.sh Upgrade to Grails 3.0 Jun 26, 2015

README.md

Build Status

Rateable Grails Plugin

This is the source for the Rateable Grails plugin which adds support for allowing users to rate things, such as plugins, books, etc.

This plugin provides allows ratings to be attached to domain objects, as well as a 5-star rating component with ajax update.

Requirements

  • Grails Version: 3.0 and above
  • JDK: 1.7 and above

Installation

Add the following to build.gradle:

 compile 'org.grails.plugins:rateable:2.0.0-SNAPSHOT'

Usage

Implement the @Rateable@ trait:

 import grails.plugins.rateable.*
 
 class Vehicle implements Rateable {
 }

On your page load the rateable resources (note that jQuery is a required dependency):

 <asset:stylesheet href="ratings.css"/>
 <asset:javascript src="ratings.js"/>

Include a tag to allow users to rate:

 <rateable:ratings bean='${myVehicle}'/>

You may need to define a rater evaluator in grails-app/conf/application.groovy. The default one looks like:

 grails.rateable.rater.evaluator = { request.user }

But if you store users in the session instead you may want this to be:

 grails.rateable.rater.evaluatorr = { session.user }

The plugin also adds some useful static methods and properties to each Rateable as defined below:

Static Methods

  • listOrderByAverageRating - lists all rated items by their average rating. Takes an optional Map parameter for pagination
  • countRated - Counts the number of rated items, good for pagination in combination with the above method.
  • topRated - The top rated item

Properties

  • ratings - Returns all the ratings for a given Rateable
  • averageRating - Returns the average rating of all the ratings
  • totalRatings - Returns the total number of ratings given to the Rateable

Methods

  • rate(user, Double rating) - Rates a Rateable for the given user and specified rating
  • userRating(user) - Returns the rating for the specified user