# SeemsRateable
Star rating gem for Rails application using jQuery plugin jRating
## Demo
Demo application, requires to sign up before rating
## Instructions
### Installation
Add this line to your application's Gemfile:
gem 'seems_rateable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install seems_rateable
### Generation
$ rails generate seems_rateable:install
Generator creates migration files, javascript files and initializer
### Prepare
Require javascript files by adding this line to application.js
#application.js
//= require_directory ./rateable
Add seems_rateable
to routes.rb file
Include stylesheet adding <%= seems_rateable_stylesheet %>
to your layout header
Also make sure you have an existing current_user
helper method
Don't forget to run
$ rake db:migrate
To prepare model add seems_rateable
to your rateable model file. You can also pass a hash of options to
customize the functionality
:dimensions
Array of dimensions e.g :dimensions => [:quality, :quantity]
:allow_update
Allowing user to re-rate his own ratings, default set to false e.g :allow_update=> true
rates
method, to get dimension rates pass an argument eg :
@object.rates
@object.rates(:quality)
@object.rates(:quantity)
This also applies to cached average rating e.g
@object.average
@object.average(:quality)
@object.average(:quantity)
And to object's raters e.g
@object.raters
@object.raters(:quality)
@object.raters(:quantity)
To track user's given ratings add seems_rateable_rater
to your rater model.
If your rater class is not "User"(e.g "Client" or "Customer") change configuration in initializer generated by this engine.
Now you can access user's ratings by @user.ratings_given
### Usage
To display star rating use helper method rating_for
in your view
#index.html.erb
rating_for @post
rating_for @post, :dimension => :quality, :class => 'post', :id => 'list'
rating_for @post, :static => true
You can specify these options :
:dimension
The dimension of the object:static
Set to true to display static star rating, default false:class
Class of the div, default set to 'rateable':id
ID of the div e.g :id => "info"
, default nil