Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoid_rating

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoid_rating

  • 0.1.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Star rating for Mongoid 4 - MongoidRating

Gem Version Dependency Status Build Status Coverage Status

Currenty this gem supports only Mongoid 4

Features

  • Multiple rating fields per model
  • Float rating marks (users can give 4.5 stars)

Installation

Add this line to your application's Gemfile:

gem 'mongoid_rating'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_rating

Usage

make model rateable:

class Post
  include Mongoid::Document
  rateable :rate
  # needed if you use rails_admin so it would not complain
  accepts_nested_attributes_for :rate_data
end
ps = Post.create()
user = User.create()

rate and unrate:

ps.rate 5, user
ps.unrate, user

Get current rating

ps.rate
=> 5.0 
ps.rate_by(user)
=> 5 

Check if user rated:

ps.rate_by?(user)
=> true 

Scopes:

Post.highest_rate
Post.rate_in(2..5)
Post.rate_in(2..5).first
=> #<Post rate_count: 1, rate_sum: 5.0, rate_average: 5.0> 
Post.rate_in(2..3).first
=> nil 

Posts rated by user:

Post.rate_by(user).first
=> #<Post rate_count: 1, rate_sum: 5.0, rate_average: 5.0> 

Credits

(c) 2013 glebtv, MIT license

Partially based on mongoid-rateable which is Copyright (c) 2011 Peter Savichev (proton), MIT license

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 30 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc