seems_rateable 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +72 -4
- data/lib/generators/seems_rateable_destroy_generator.rb +19 -0
- data/lib/seems_rateable/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWYwNDQ2NGZmYmRjZTg0ZGIxNzA5ZWMzMjI2ZDA5OWE4ZWMxOTRhMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDRiN2U5NmVlMGM5YWM0MGM1ZGIxMTBjMGQ4ODQ3NTdiZmNjOGNhOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mjg0OWY5ZTFjYmM3OTNhN2E1YTVlOWQzYWEwOGIyMDk4YjRhM2Y4ZDQ5ZTI5
|
10
|
+
Y2IyZWI2NWQzNDAzOWE0Mzc2ZTc3Yjk0OWM4NDQzNTU0OGE3ZmJiM2Y3MjQ4
|
11
|
+
OGIxM2RjNjA0ZjY5MDRkMjkzMzk1NzBhNGEyNjhjNDlkM2VjMDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTViMzBjN2U5MWYxZmQxNWUwZjk1MjFiYTIwNDgyZWE3Y2U2MDExY2I2MDRm
|
14
|
+
NjgxZTM4ZTg4ZjNkY2EyNjE2NmNiNWRiYzc1YWFiZThiMTczZGViMTk4YjUy
|
15
|
+
ZDJkNjU4NjE0ZGE4MzlmZDE1Y2VmYzE0YTcwZjY1NjY1ZjVkMWI=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SeemsRateable
|
2
2
|
|
3
|
-
Star rating gem for Rails application using jQuery plugin jRating
|
3
|
+
Star rating gem for Rails application using jQuery plugin <a href="http://www.myjqueryplugins.com/jquery-plugin/jrating">jRating</a>
|
4
4
|
|
5
5
|
## Demo
|
6
6
|
|
@@ -26,11 +26,79 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
$ rails g seems_rateable User
|
28
28
|
|
29
|
-
Generator takes one argument which is name of an existing user model e.g User, Client, Player ... <br>
|
30
|
-
The generator creates necessary model, controller and asset files. It also creates route and migration files that are already migrated
|
29
|
+
Generator takes one argument which is the name of an existing user model e.g User, Client, Player ... <br>
|
30
|
+
The generator creates necessary model, controller and asset files. It also creates route and migration files that are already being migrated
|
31
31
|
|
32
|
-
###
|
32
|
+
### Prepare
|
33
|
+
|
34
|
+
Include Javascript files adding these lines to application.js
|
35
|
+
|
36
|
+
#application.js
|
37
|
+
//= require rateable/jRating.jquery
|
38
|
+
//= require rateable/rateable.jquery
|
39
|
+
|
40
|
+
Include CSS file adding <code><%= seems_rateable_style %></code> to your layaut head tag
|
41
|
+
|
42
|
+
Also make sure you have an existing <code>current_user</code> object. If not, add something like this to your application controller
|
43
|
+
|
44
|
+
#application_controller.rb
|
45
|
+
helper_method :current_user
|
46
|
+
private
|
47
|
+
def current_user
|
48
|
+
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
To prepare model be rateable add <code>seems_rateable</code> to your model file. You can also pass a hash of options to
|
52
|
+
customize the functionality
|
53
|
+
|
54
|
+
<ul>
|
55
|
+
<li><code>:dimensions</code> Array of dimensions e.g. <code>:dimensions => [:quality, :price, :performance]</code></li>
|
56
|
+
<li><code>:allow_update</code> Allowing user to re-rate his own ratings, default set to false e.g <code>:allow_update=> true</code>
|
57
|
+
</ul>
|
58
|
+
|
59
|
+
class Computer < ActiveRecord::Base
|
60
|
+
seems_rateable :dimensions => [:quality, :price, :performance], :allow_update => true
|
61
|
+
end
|
62
|
+
|
63
|
+
Each object of the model now gain these methods :
|
64
|
+
<ul>
|
65
|
+
<li><code>@computer.rates_without_dimension</code> returns array of ratings given to the object</li>
|
66
|
+
<li><code>@computer.raters_without_dimension</code> returns array of users that rated the object</li>
|
67
|
+
<li><code>@computer.rate_average_without_dimension</code> returns cached database object containing average rate and quantity of given ratings of the object</li>
|
68
|
+
</ul>
|
69
|
+
|
70
|
+
Depending on the passed dimensions your object also gain these methods :
|
71
|
+
|
72
|
+
<ul>
|
73
|
+
<li><code>@computer.dimension_rates</code> e.g <code>@computer.quality_rates</code></li>
|
74
|
+
<li><code>@computer.dimension_raters</code> e.g <code>@computer.price_raters</code></li>
|
75
|
+
<li><code>@computer.dimension_average</code> e.g <code>@computer.performance_average</code></li>
|
76
|
+
</ul>
|
77
|
+
|
78
|
+
To track user's given ratings add <code>seems_rateable_rater</code> to your user model.
|
79
|
+
Now you can access user's ratings by <code>@user.ratings_given</code>
|
80
|
+
|
81
|
+
### Usage
|
82
|
+
|
83
|
+
To display star rating use helper method <code>rating_for</code> in your view
|
84
|
+
|
85
|
+
#index.html.erb
|
86
|
+
|
87
|
+
rating_for @computer
|
88
|
+
|
89
|
+
rating_for @computer, :dimension => :price, :id => "storage"
|
90
|
+
|
91
|
+
rating_for @computer, :static => true
|
92
|
+
|
93
|
+
You can specify these options :
|
94
|
+
<ul>
|
95
|
+
<li><code>:dimension</code>The dimension of the object</li>
|
96
|
+
<li><code>:static</code>Set to true to display static star rating, default false</li>
|
97
|
+
<li><code>:id</code>ID of the div e.g <code>:id => "info"</code>, default nil</li>
|
98
|
+
</ul>
|
33
99
|
|
100
|
+
To edit the javascript options locate rateable.jquery.js file in /vendor/assets/javascripts/rateable/.
|
101
|
+
The javascript options are explained directly in the file
|
34
102
|
|
35
103
|
## Contributing
|
36
104
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
class SeemsRateableDestroyGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
def remove_asset_files
|
5
|
+
FileUtils.remove_dir('vendor/assets/stylesheets/rateable')
|
6
|
+
FileUtils.remove_dir('vendor/assets/javascripts/rateable')
|
7
|
+
FileUtils.remove_dir('vendor/assets/images/rateable')
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove_model_files
|
11
|
+
FileUtils.rm('app/models/rate.rb')
|
12
|
+
FileUtils.rm('app/models/cached_rating.rb')
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_controller_file
|
16
|
+
FileUtils.rm('app/controllers/ratings_controller.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seems_rateable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Toth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/generators/seems_rateable/templates/model.rb
|
78
78
|
- lib/generators/seems_rateable/templates/rate_migration.rb
|
79
79
|
- lib/generators/seems_rateable/templates/stylesheets/jRating.jquery.css
|
80
|
+
- lib/generators/seems_rateable_destroy_generator.rb
|
80
81
|
- lib/seems_rateable.rb
|
81
82
|
- lib/seems_rateable/helpers.rb
|
82
83
|
- lib/seems_rateable/record.rb
|