No commit activity in last 3 years
No release in over 3 years
Rate multiple attributes of models with Active Record.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

RateableAttributes¶ ↑

RateableAttributes is a re-implementation of ActsAsRateable for multiple attribute support.

Usage¶ ↑

Installation¶ ↑

To install as plugin:

script/plugin install git://github.com/sdepold/rateable_attributes.git

Preparation¶ ↑

In order to create the rating table just run the following commands:

script/generate rateable_attributes
rake db:migrate

This will generate a migration. Run rake db:migrate.

In the model¶ ↑

rateable_attributes :graphics, :sound, :whatever, :range => 1..5

This allows you to rate the model for the attributes graphics, sound and whatever. To do so use

my_model.rate(3, a_user[, :the_attribute]) # you can just ignore the attribute to create a general rating
my_model.rate_graphics(3, a_user) # equals my_model.rate(3, a_user, :graphics)

Visualizing the average rating¶ ↑

RateableAttributes a method to the model called visualize_average_rating. It can be called the following options:

  • attribute = The attribute you want to display. Default: nil

  • image_rated = The image/symbol you wish to be shown as reached rating. Default: A yellow star

  • image_unrated = The image/symbol you wish to be shown as unreached rating. Default: A white star

  • image_hover = The image/symbol you wish to be shown when hovering one of the rating images (see next option). Default: An orange star

  • enable_rating = Should the user be able to click and rate?

  • click_url = The URL which gets called, when a user clicked on a star to rate the model.

When you enable the rating option, the controller should return a json object as follows:

{new_rating: 2}

Important as well is, that you include the generated javascript file. Just do the following in your documents head:

= javascript_include_tag "rateable_attributes.js"

The javascript uses the prototype plugin. Feel free to change it for JQuery if you are using it.