Giter Site home page Giter Site logo

bergholdt / acts_as_rateable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from antonzaytsev/acts_as_rateable

0.0 2.0 0.0 108 KB

in plans fully support and use all features rails 3 (original : https://github.com/leviathan/acts_as_rateable)

License: MIT License

Ruby 100.00%

acts_as_rateable's Introduction

Acts As Rateable

Acts_as_rateable is a plugin released under the MIT license. It makes activerecord models rateable through a polymorphic association and optionally logs which user rated which model. In this case, one user can rate an object once. Used on cotcot.hu for article rating, sponsored quizzes, etc.

A ‘free text’ attribute has been added to the pure numerical rating. The ‘free text’ serves as the user’s rating description or comment.

Install

You can easily install gem by adding this line into your Gemfile:

gem "acts_as_rateable", :git => "git://github.com/anton-zaytsev/acts_as_rateable.git"

After you install Acts As Rateable and add it to your Gemfile, you need to run the generator:

rails generate acts_as_rateable

The generator will add new migration, that’s why the next is run migration:

rake db:migrate

Now insert ‘acts_as_rateable’ into your model, and don’t forget restart your application.

class Post < ActiveRecord::Base
  acts_as_rateable
end

Now you can rate it ( 1-# )or calculate the average rating.

# rate for selected post
@post.rate_it( 4, current_user ) #=> true || false

# average rating of selected post
@post.average_rating #=> 4.0
@post.average_rating_round #=> 4
@post.average_rating_percent #=> 80

# check if selected post rated by user
@post.rated_by?( current_user ) #=> instance of rating model || false

@post.parse_ratings(:json) #=> JSON formatted string containing the post's ratings

# find posts with rating '4'
Post.find_average_of( 4 ) #=> array

See lib/acts_as_rateable.rb for further details!

# Notes

Jinzhu - generator is compatible with rails 3.

Copyright © 2011 Anton Zaytsev, antonzaytsev.com , released under the MIT license

Copyright © 2007-2010 Ferenc Fekete, feketeferenc.hu , released under the MIT license

Copyright © 2011 Joerg Polakowski, mobile-melting.de , released under the MIT license

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.