All Projects → proton → Mongoid_rateable

proton / Mongoid_rateable

Licence: mit
Rating functionality for Mongoid documents

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Mongoid rateable

Tomatoes
Pomodoro Technique® online time tracker
Stars: ✭ 344 (+483.05%)
Mutual labels:  mongoid, rails
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (+69.49%)
Mutual labels:  mongoid, rails
Algoliasearch Rails
AlgoliaSearch integration to your favorite ORM
Stars: ✭ 352 (+496.61%)
Mutual labels:  mongoid, rails
Simple token authentication
Simple (but safe) token authentication for Rails apps or API with Devise.
Stars: ✭ 1,474 (+2398.31%)
Mutual labels:  mongoid, rails
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+1461.02%)
Mutual labels:  mongoid, rails
Coderdojo.jp
☯️ CoderDojo Japan (@coderdojo-japan) official website developed by Ruby on Rails with @YassLab team. 💎
Stars: ✭ 50 (-15.25%)
Mutual labels:  rails
Danbooru
A taggable image board written in Rails 6.
Stars: ✭ 1,077 (+1725.42%)
Mutual labels:  rails
Kaminari
⚡ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Ruby webapps
Stars: ✭ 8,085 (+13603.39%)
Mutual labels:  rails
Jsonapi parameters
Rails-way to consume JSON:API input
Stars: ✭ 50 (-15.25%)
Mutual labels:  rails
Letsencrypt heroku
Automated letsencrypt setup for heroku
Stars: ✭ 58 (-1.69%)
Mutual labels:  rails
Manageiq
ManageIQ Open-Source Management Platform
Stars: ✭ 1,089 (+1745.76%)
Mutual labels:  rails
Ss Panel Rails
rm
Stars: ✭ 53 (-10.17%)
Mutual labels:  rails
Logidze
Database changes log for Rails
Stars: ✭ 1,060 (+1696.61%)
Mutual labels:  rails
Lofocats ui
LofoCats UI is a simple web application consuming the LofoCats API, built with Ruby on Rails 🐱
Stars: ✭ 54 (-8.47%)
Mutual labels:  rails
Action mailer matchers
ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.
Stars: ✭ 50 (-15.25%)
Mutual labels:  rails
Tripod
ActiveModel-style Ruby ORM for RDF Linked Data. Works with SPARQL 1.1 HTTP endpoints.
Stars: ✭ 56 (-5.08%)
Mutual labels:  rails
Simple form
Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
Stars: ✭ 7,877 (+13250.85%)
Mutual labels:  rails
Adminlte Rails Template
Rails template application of an admin panel with the AdminLTE theme integrated.
Stars: ✭ 53 (-10.17%)
Mutual labels:  rails
Consul
Consul - Open Government and E-Participation Web Software
Stars: ✭ 1,088 (+1744.07%)
Mutual labels:  rails
Salorhospitality
The innovative Point of Sale Solution serving the Hospitality Industry
Stars: ✭ 52 (-11.86%)
Mutual labels:  rails

= Mongoid::Rateable

Provides fields and methods for the rating manipulation on Mongoid documents

{}[http://travis-ci.org/proton/mongoid_rateable]

Lastest version of Mongoid:Rateable requires mongoid 3, 4, 5 and 6.

If you need a mongoid 2 support, look at mongoid_rateable 0.1.7.

== Support us

{}[https://flattr.com/submit/auto?user_id=proton&url=https://github.com/proton/mongoid_rateable/&title=MongoidRateable&language=&tags=github&category=software]

== Installation

Add to Gemfile:

gem 'mongoid_rateable'

== Getting Started

Simply use the rateable macro from any class that is a Mongoid Document.

This macro will include Mongoid::Rateable into the class and configure the rating functionality using the options hash. For any option not present, the default option value will be used.

class Post
  include Mongoid::Document

  rateable range: (-5..7), raters: [User, Admin]
end

You can also set the default_rater

class Post
  include Mongoid::Document

  # will simply call the 'owner' method to find the default rater
  # if no rater given when rating

  rateable range: (-5..7), raters: [User, Admin], default_rater: 'owner'
end

class Post
  include Mongoid::Document

  # if given a block, this will be used as a dynamic way to find
  # the a rater in case no rater is passed in as the 2nd argument to
  # the rate method

  rateable range: (-5..7), raters: [User, Admin] do
    # will by default be rated by the last user
    # who made a comment to this post!
    comments.last.user
  end
end

Note: For even more control over the configuration, see the ClassMethods module code in rateable.rb.

== Cast Rates

You can rate by passing an integer and a rater model to the "rate" method:

@post = Post.first
@user = User.where(:name => 'Bill') # or more likely, current_user

@post.rate 1, @user     # I like this!
@post.rate -1, @user    # I don't like this!
@post.rate 5, @user     # I LOVE this!
@post.rate -10, @user   # Delete it from the Internet!

# Many users love this!
@post.rate 5, @users     # They LOVIN' it!

Rates have weight (1 by default)

@post.rate 5, @user, 3     # Rate @post with weight 3 (@user has high karma)
@post.rate 3, @user, 1     # Rate @post with weight 1 (@user has low karma)

You can unrate by using "unrate" method:

@post.unrate @user

And don't forget to save rateable object:

@post.save

Sure, you can rate and save in one function:

@post.rate_and_save(3, @user)
@post.unrate_and_save(@user)

== Additional Functionality

You'll often want to know if a user already rated post. Simple:

@post.rated_by? @user   # True if it rated by user

And if someone rated it:

@post.rated?            # True if it rated by someone

You can get user mark:

@post.user_mark(@user)  # Mark or nil (if not rated by user)

Or marks:

@post.user_marks([@user1, @user2])  # Hash {user.id => mark}

You can also get a tally of the number of rates cast:

@post.rate_count        # Just one so far!

You can get a total weight of post rates:

@post.rate_weight        # Just one so far!

And you can get the average rating:

@post.rating            # rates / rate_weight

And you can get the average rating without weights (It calculates realtime, so it can be slow):

@post.unweighted_rating # rates without weights / rate_count

And you can get the previous rating and delta:

@post.previous_rating
@post.rating_delta      # rating - previous_rating

== Scopes

You can get rated or unrated posts:

Post.rated
Post.unrated

You can get posts rated by someone:

Post.rated_by(@user)

You can get posts with some rating:

Post.with_rating(2..5)
Post.with_rating(0..10)
Post.with_rating(-2..2)

You can get most rated and highest rated posts: (Sorry, this method doesn't work with embedded documents)

Post.highest_rated      # 10 (or less) highest rated posts
Post.highest_rated(5)   # 5 (or less) highest rated posts

== Contributing to Mongoid::Rateable

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 Peter Savichev (proton). See LICENSE.txt for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].