rails_rateable 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -6
- data/lib/app/models/rails_rateable.rb +4 -6
- data/lib/rails_rateable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 025c051445f757aaa2aa31f8dc8aee7dcfd00122
|
4
|
+
data.tar.gz: c61f328b9fbe752bbdb76c7c02546b3f3d912729
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edddebccb41fb830a22b89c0b59ae2be4c35bf66c175cbf44393570270a5df6094c0e51fa4bf29560900e19edca868e9d6f87e09b808871973a4d1dd8fb83065
|
7
|
+
data.tar.gz: 02f81100bb78c24e8dae26be9c55a8b2e7a47acfd10943cb3da6c43ee63c71d79ac13288a8e44bd313ffd856a1dd0aa926375ca93037a1ec5dd3c3c295a5459b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Rateble
|
2
2
|
|
3
|
-
|
3
|
+
rails_rateable is a rails gem providing a rating interface for ActiveRecord models.
|
4
4
|
It is compitable only with Rails 3 and above. It is released under the MIT license.
|
5
5
|
|
6
6
|
|
@@ -40,7 +40,19 @@ Add 'include RailsRateable' to the modal you want to make rateable, then restart
|
|
40
40
|
include RailsRateable
|
41
41
|
end
|
42
42
|
|
43
|
-
Now your model is extended by the
|
43
|
+
Now your model is extended by the Gem, you can rate it (1-#) or calculate the average rating.
|
44
|
+
|
45
|
+
|
46
|
+
By default max_rating is 5 i,e user can give rating from 1 to 5 . You can override it by passing max_rating parameter
|
47
|
+
to rails_rateable
|
48
|
+
|
49
|
+
In Below example, Comment model is made rateable and max_rating set to 10, so for comment user can provide rating between 1 to 10
|
50
|
+
|
51
|
+
class Comment < ActiveRecord::Base
|
52
|
+
include RailsRateable
|
53
|
+
rails_rateable :max_rating => 10
|
54
|
+
end
|
55
|
+
|
44
56
|
|
45
57
|
@movie.rate_it(4, current_user)
|
46
58
|
|
@@ -53,11 +65,11 @@ Now your model is extended by the plugin, you can rate it (1-#) or calculate the
|
|
53
65
|
|
54
66
|
Movie.find_top_rated #=> top rated records
|
55
67
|
|
56
|
-
|
68
|
+
By default 20 top rated result will be returned. Youu can override it by passing numer of record you want.
|
69
|
+
|
70
|
+
Movie.find_top_rated(40) # will return 40 records
|
71
|
+
|
57
72
|
|
58
|
-
class Comment < ActiveRecord::Base
|
59
|
-
acts_as_rateable :max_rating => 10
|
60
|
-
end
|
61
73
|
|
62
74
|
|
63
75
|
CREDIT:
|
@@ -7,18 +7,16 @@ module RailsRateable
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
#put class method here to be trigger as say User.method_name
|
10
|
-
def
|
10
|
+
def rails_rateable(options = {})
|
11
11
|
unless respond_to?(:max_rating)
|
12
12
|
class_attribute :max_rating
|
13
13
|
self.max_rating = options[:max_rating] || 5
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def find_top_rated(
|
18
|
-
|
19
|
-
|
20
|
-
find_params[:limit] = 20 unless find_params.key?(:limit)
|
21
|
-
find(:all, find_params)
|
17
|
+
def find_top_rated(limit = nil)
|
18
|
+
limit = 20 unless limit
|
19
|
+
includes(:rating).order('ratings.average_rating DESC').limit(limit)
|
22
20
|
end
|
23
21
|
|
24
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_rateable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|