Last updated by admin 2 years ago
Last updated by jasenj1 2 years ago
Rateable Plugin
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: 1.1 and above
- JDK: 1.5 and above
- YUI 2.6.1
Installation
grails install-plugin rateable
Usage
Implement the
Rateable interface:
import org.grails.rateable.*class Vehicle implements Rateable {
}On your page load the rateable resources:
Include a tag to allow users to rate:
<rateable:ratings bean='${myVehicle}'/>
Like the
Commentable Plugin, to use you may need to define a rater evaluator in grails-app/conf/Config.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.
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
Last updated by admin 2 years ago
Last updated by admin 2 years ago