trustieforge/lib/seems_rateable
yanxd d9cadfc43e 未登录500报错 2014-04-23 09:20:09 +08:00
..
app 未登录500报错 2014-04-23 09:20:09 +08:00
bin seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
config seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
lib seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
Gemfile seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
MIT-LICENSE seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
README.md seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
Rakefile seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00
seems_rateable.gemspec seem_rateable to lib, using Engine setting routes 2014-04-23 08:51:46 +08:00

README.md

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

  • :dimensionsArray of dimensions e.g :dimensions => [:quality, :quantity]
  • :allow_updateAllowing user to re-rate his own ratings, default set to false e.g :allow_update=> true
class Post < ActiveRecord::Base
	seems_rateable :allow_update => true, :dimensions => [:quality, :length]
end

To access object's rates use 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 :

  • :dimensionThe dimension of the object
  • :staticSet to true to display static star rating, default false
  • :classClass of the div, default set to 'rateable'
  • :idID of the div e.g :id => "info", default nil

To edit the javascript options locate rateable.js file in /app/assets/javascripts/rateable/. The javascript options are explained directly in the file

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request