Currently star buttons are a put request, not a post request like they should be due to time constraints. Should be fixed in a future version.
Patches welcome! I do test my own stuff but until I find a nice and easy way to include rspec in plugins, they won’t come with the specs.
To install, type
script/generate rateable [--by_user] [--with-categories]
—by-user will associate your ratings to a user model. Hopefully you’ve got one already.
—with-categories will add multiple rating categories. Specify them in your model as shown.
In your model.
is_rateable :upto => 5 # it defaults :upto => 5
is_rateable :categories => [:writing, :artwork]
In your view.
render_rating(@book, :type => :interactive_stars)
render_rating(@book) # If you want to also see 1/5 Stars
If a user rates more than twice (or twice in the same category), it will replace their older rating with a new rating.
Add a method to your books_controller like so:
@book = Book.find(params[:id])
unless @book.rate(params[:rating].to_i, :category => params[:category], :ip => request.remote_ip)
flash[:notice] = "You have already voted on this book"
If you’re using multiple categories (writing, artwork, editing) you can supply the :category option to the render_rating view helper.
This will display the category rating of the model. Then calling render_rating without a :category option will display the average rating
across all categories.
render_rating(@book, :type => :interactive_stars, :category => :writing)
render_rating(@book, :type => :interactive_stars, :category => :artwork)
render_rating(@book) # Overall rating is average of two category ratings
If you want to see ratings for a specific user rather than global averages, you can also specify the :user option and pass it the
user for whom you wish to obtain ratings.
render_rating(@book, :type => :interactive_stars, :user => user)
- Zach Inglis
- Nathan Arnold
- Tim Pope
- Nick Plante
- Rogie King – CSS for Stars
- Some code from restful_authentication by Rick Olson
Copyright © 2008 Zach Inglis, released under the MIT license