Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.
/ seems_rateable Public archive

Star rating gem for rails applications. Uses jRating jquery plugin.

License

Notifications You must be signed in to change notification settings

petertoth/seems_rateable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 g seems_rateable User

Generator takes one argument which is the name of an existing user model e.g User, Client, Player ...
The generator creates necessary model, controller and asset files. It also creates route and migration files that are already being migrated

Prepare

Include Javascript files adding these lines to application.js

 #application.js    
 //= require rateable/jRating.jquery
 //= require rateable/rateable.jquery

Include CSS file adding <%= seems_rateable_style %> to your layaut head tag

Also make sure you have an existing current_user object. If not, add something like this to your application controller

#application_controller.rb
helper_method :current_user
private
def current_user
	@current_user ||= User.find(session[:user_id]) if session[:user_id]
end 

To prepare model be rateable add seems_rateable to your model file. You can also pass a hash of options to customize the functionality

  • :dimensions Array of dimensions e.g. :dimensions => [:quality, :price, :performance]
  • :allow_update Allowing user to re-rate his own ratings, default set to false e.g :allow_update=> true
class Computer < ActiveRecord::Base
    seems_rateable :dimensions => [:quality, :price, :performance], :allow_update => true
end

Each object of the model now gain these methods :

  • @computer.rates_without_dimension returns array of ratings given to the object
  • @computer.raters_without_dimension returns array of users that rated the object
  • @computer.rate_average_without_dimension returns cached database object containing average rate and quantity of given ratings of the object

Depending on the passed dimensions your object also gain these methods :

  • @computer.dimension_rates e.g @computer.quality_rates
  • @computer.dimension_raters e.g @computer.price_raters
  • @computer.dimension_average e.g @computer.performance_average

To track user's given ratings add seems_rateable_rater to your user model. 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 @computer

rating_for @computer, :dimension => :price, :id => "storage"

rating_for @computer, :static => true

You can specify these options :

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

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

Removal

To remove gem files simply execute rails g seems_rateable_destroy in terminal. Neither migration files nor database tables will be destroyed.

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

About

Star rating gem for rails applications. Uses jRating jquery plugin.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •