Need help with ajaxful-rating?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

424 Stars 134 Forks 91 Commits 31 Opened issues


Provides a simple way to add rating functionality to your application.

Services available


Need anything else?

Contributors list

# 168,861
45 commits
# 68,112
6 commits
# 92,338
4 commits
# 374,247
3 commits
# 307,725
2 commits
# 168,068
1 commit
# 482,102
1 commit
# 154,090
1 commit

h1. Ajaxful Rating

Provides a simple way to add rating functionality to your application.


h2. Repository

Find it at "":

h2. Demo

You can find a demo working app for this plugin at "": Just migrate and run...

Or view it live: "":

h2. Instructions

h3. Install

To install the gem run the next command:

@gem install [email protected]

You can configure it in your environment.rb file also:

@config.gem "ajaxful_rating"@

h3. Generate

@script/generate ajaxful_rating [email protected]

The generator takes one argument: UserModelName, which is the name of your current user model. This is necessary to link both the rate and user models.

Also this generator copies the necesary images, styles, etc.

Example: I suppose you have generated already an authenticated model...

script/generate authenticated user sessions
script/generate ajaxful_rating user

So this call will create a Rate model and will link it to your User model.

h3. Prepare

To let a model be rateable just add @ajaxful[email protected] You can pass a hash of options to customise this call: * @:[email protected] Max number of stars that can be submitted. * @:allow[email protected] Set to true if you want users to be able to update their votes. * @:[email protected] Name of the column for storing the cached rating average. * @:[email protected] Array of dimensions. Allows to rate the model on various specs, like for example: a car could be rated for its speed, beauty or price.

class Car < ActiveRecord::Base
  ajaxful_rateable :stars => 10, :dimensions => [:speed, :beauty, :price]

Then you need to add a call @[email protected] in the user model to make your @[email protected] model able to rate objects.

class User < ActiveRecord::Base

Finally, as a mere recomendation to make it even easier, modify your routes to map a rate action:

@map.resources :cars, :member => {:rate => :post}@

h3. Use it

To add the star links you need to call the helper method @ratings[email protected] It tries to call @current[email protected] method as the rater instance. You can pass @:[email protected] as the second param to display only the static stars (not clickables). And also you can pass the dimension you want to show the ratings for.


#To display static stars:

#To display the ratings for a dimension:
 :speed %>

Or you can specify a custom user instance by passing it as parameter.

By default ratingsfor will display the average user rating. If you would like it to display the rating for the currentuser, then set the :showuserrating parameter to true. For example:

# To display the rating for the current user (current_user):
 true %>

# To display the rating for the user specified by @user:
 true %>

There's a condition here, if you didn't add the route @[email protected] to your resource (as shown above) or you named it different, you'll need to pass the url to the correct action in your controller:

 {:url => your_rate_path(@article)} %>

h3. Important!

To display the stars properly you need to add a call in the head of your layout, which will generate the required CSS style for the list. Also don't forget to include the javascripts.

It's also important to note that this call MUST be within your head tags in your layout, as for now it seems to doesn't work with the @[email protected] tag.

  #within the head tags of your layout...

When a user submits a rating it will call the action in your controller, for example (if you added the @[email protected] route):

  def rate
    @car = Car.find(params[:id])
    @car.rate(params[:stars], current_user, params[:dimension])
    render :update do |page|
      page.replace_html @car.wrapper_dom_id(params), ratings_for(@car, params.merge(:wrap => false))
      page.visual_effect :highlight, @car.wrapper_dom_id(params)

There are some more options for this helper, please see the rdoc for details.

h3. Dimensions

From now on you can pass an optional parameter to the @[email protected] method for your rateable object to retrieve the corresponding rates for the dimension you want.

For example, you defined these dimensions:

class Car < ActiveRecord::Base
  ajaxful_rateable :dimensions => [:speed, :beauty, :price]

And hence you can call @car.rates(:price)@ for the price rates or @car.rates(:speed)@ for the speed ratings and so on.

h3. Namespaces

If you use the plugin inside a namespace you’ll need to specify the rating url which should points to a controller inside a namespace. Your files should be like these:

map.namespace :admin do |admin|
  admin.resources :articles, :member => {:rate => :post}

 {:url => rate_admin_article_path(@article)} %>

h3. Cache

To cache the model's rating average add a column named @[email protected] to your model table:

class AddRatingAverageToArticles < ActiveRecord::Migration
  def self.up
    add_column :articles, :rating_average, :decimal, :default => 0, :precision => 6, :scale => 2

  def self.down
    remove_column :articles, :rating_average

If you want to customise the name of the cache column just pass it in the options hash:

class Article < ActiveRecord::Base
  ajaxful_rateable :cache_column => :my_cached_rating

To use caching with dimensions, make sure you have a cache column defined for each dimension you want cached. So if you want to cache the @[email protected] dimension, you’ll need to have a column called @ratingaverage[email protected] on the articles table. If you use a custom cache column name, follow the pattern @cachecolumnnamedimension[email protected] to add cache columns for dimensions.

h2. About backwards compatibility

Version 2.0 of the plugin works only from Rails 2.2 and on. It uses the module @[email protected] which is new in rails 2.2. Please note that you can use it in past versions as long as you customise the source code.

I decided to jump directly to version 2.0 because there are many important changes. You can always checkout the version 1.0 from the repository though.

h2. Feedback

If you find bugs please open a ticket at "":

I'll really appreciate your feedback, please contact me at e[at]dgar[dot]org

h2. Credits

The helper's style is from "komodomedia": with author's permission.

If you need the psd files of the stars you can grab them "here":

Thanks to "bborn": for the dimensions base implementation.

h2. License

This code is released under Creative Commons Attribution-Share Alike 3.0 license.


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.