Code Monkey home page Code Monkey logo

letsrate's Introduction

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'

Generate

rails g letsrate User

The generator takes one argument which is the name of your existing devise 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 devise user model which name is User. The devise generator and letsrate generator should be like below

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 should add the letsrate_rateable function with its dimensions option. You can add multiple dimensions.

class Car < ActiveRecord::Base
  letsrate_rateable "speed", "engine", "price"
end

Then you need to add a call letsrate_rater in the user model.

class User < ActiveRecord::Base
  letsrate_rater
end

Using

There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the new rating value from authenticated user.

<%# 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" %>

Feedback

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

letsrate's People

Contributors

muratguzel avatar skyeagle avatar styx avatar thekindofme avatar petehuang avatar klaustrainer avatar

Watchers

James Cloos avatar Carl Noresson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.