8000 GitHub - emjot/letsrate: The best way to add rating capabilities to your rails application and your activerecord models.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 22, 2022. It is now read-only.
/ letsrate Public archive
forked from muratguzel/letsrate

The best way to add rating capabilities to your rails application and your activerecord models.

Notifications You must be signed in to change notification settings

emjot/letsrate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Letsrate Rating Gem

Provides the best way to add rating capabilites to your Rails application with jQuery Raty plugin.

Build Status Dependency Status Code Climate

Repository

Find it at github.com/muratguzel/letsrate

Instructions

Install

Add the letsrate gem into your Gemfile

gem 'letsrate', '~> 1.0.9'

Generate

rails g letsrate User

The generator takes one argument which is the name of your existing user model UserModelName. This is necessary to bind the user and rating datas. Also the generator copies necessary files (jquery raty plugin files, star icons and javascripts)

Example:

Suppose you will have a user model which name is User. You could generate one with the devise generator:

rails g devise:install
rails g devise user

rails g letsrate user # => user is the model generated by devise

This generator will create Rate and RatingCache models and link to your user model.

Prepare

I suppose you have a car model

rails g model car name:string

You have to include the Letsrate::Rateable concern in your car model to enable a one dimensional rating.

class Car < ActiveRecord::Base
  include Letsrate::Rateable
end

You can also define multiple additional rating dimensions by using the rateable_dimensions class method.

class Car < ActiveRecord::Base
  include Letsrate::Rateable

  rateable_dimensions "speed", "engine", "price"
end

Then you need to include the Letsrate::Rater concern in the user model.

class User < ActiveRecord::Base
  include Letsrate::Rater
end

Using

There are two helper methods to render ratings:

You can user the rating_for helper method to show the average rating for a given object.

<%# show.html.erb -> /cars/1 %>

Rating :  <%= rating_for @car %>

If you defined multiple rating dimensions you can pass them to the helper.

<%# show.html.erb -> /cars/1 %>

Speed :  <%= rating_for @car, "speed" %>
Engine : <%= rating_for @car, "engine" %>
Price :  <%= rating_for @car, "price" %>

If you need to change the star number, you should use star option like below.

Speed : <%= rating_for @car, "speed", :star => 10 %>
Speed : <%= rating_for @car, "engine", :star => 7 %>
Speed : <%= rating_for @car, "price" %>

You can use the user_rating_for helper method to show the star rating for a given user.

Speed : <%= user_rating_for @car, current_user, "speed", :star => 10 %>

Feedback

If you find bugs please open a ticket at https://github.com/muratguzel/letsrate/issues

About

The best way to add rating capabilities to your rails application and your activerecord models.

Resources

Stars

Watchers

Forks

Packages

No packages published
3100

Languages

  • JavaScript 56.3%
  • Ruby 43.7%
0