Git Product home page Git Product logo

rateable_attributes's Introduction

RateableAttributes

RateableAttributes is a re-implementation of ActsAsRateable for multiple attribute support.

Usage

Installation

To install as plugin:

script/plugin install git://github.com/sdepold/rateable_attributes.git

Preparation

In order to create the rating table just run the following commands:

script/generate rateable_attributes
rake db:migrate

This will generate a migration. Run rake db:migrate.

In the model

rateable_attributes :graphics, :sound, :whatever, :range => 1..5

This allows you to rate the model for the attributes graphics, sound and whatever. To do so use

my_model.rate(3, a_user[, :the_attribute]) # you can just ignore the attribute to create a general rating
my_model.rate_graphics(3, a_user) # equals my_model.rate(3, a_user, :graphics)

Visualizing the average rating

RateableAttributes a method to the model called visualize_average_rating. It can be called the following options:

  • attribute = The attribute you want to display. Default: nil

  • image_rated = The image/symbol you wish to be shown as reached rating. Default: A yellow star

  • image_unrated = The image/symbol you wish to be shown as unreached rating. Default: A white star

  • image_hover = The image/symbol you wish to be shown when hovering one of the rating images (see next option). Default: An orange star

  • enable_rating = Should the user be able to click and rate?

  • click_url = The URL which gets called, when a user clicked on a star to rate the model.

When you enable the rating option, the controller should return a json object as follows:

{new_rating: 2}

Important as well is, that you include the generated javascript file. Just do the following in your documents head:

= javascript_include_tag "rateable_attributes.js"

The javascript uses the prototype plugin. Feel free to change it for JQuery if you are using it.

rateable_attributes's People

Contributors

sdepold avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  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.