letsrate 1.0.7 → 1.0.8
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.
- data/.travis.yml +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +80 -58
- data/Rakefile +11 -0
- data/letsrate.gemspec +1 -1
- data/lib/letsrate/model.rb +1 -1
- data/lib/letsrate/version.rb +1 -1
- metadata +4 -5
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
# Letsrate Rating Gem
|
1
|
+
# Letsrate Rating Gem
|
2
2
|
|
3
3
|
Provides the best way to add rating capabilites to your Rails application with jQuery Raty plugin.
|
4
4
|
|
5
|
+
[](http://travis-ci.org/muratguzel/letsrate)
|
6
|
+
[](https://gemnasium.com/muratguzel/letsrate)
|
7
|
+
[](https://codeclimate.com/github/muratguzel/letsrate)
|
8
|
+
|
5
9
|
## Repository
|
6
10
|
|
7
|
-
Find it at [github.com/muratguzel/letsrate](github.com/muratguzel/letsrate)
|
11
|
+
Find it at [github.com/muratguzel/letsrate](https://github.com/muratguzel/letsrate)
|
8
12
|
|
9
13
|
## Instructions
|
10
14
|
|
@@ -12,82 +16,100 @@ Find it at [github.com/muratguzel/letsrate](github.com/muratguzel/letsrate)
|
|
12
16
|
|
13
17
|
Add the letsrate gem into your Gemfile
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
```ruby
|
20
|
+
gem 'letsrate'
|
21
|
+
```
|
22
|
+
|
17
23
|
### Generate
|
18
24
|
|
19
|
-
|
25
|
+
```
|
26
|
+
rails g letsrate User
|
27
|
+
```
|
20
28
|
|
21
29
|
The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating datas.
|
22
30
|
Also the generator copies necessary files (jquery raty plugin files, star icons and javascripts)
|
23
31
|
|
24
|
-
Example:
|
32
|
+
Example:
|
33
|
+
|
34
|
+
Suppose you will have a devise user model which name is User. The devise generator and letsrate generator should be like below
|
25
35
|
|
26
|
-
|
36
|
+
```
|
37
|
+
rails g devise:install
|
38
|
+
rails g devise user
|
27
39
|
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
rails g letsrate user # => user is the model generated by devise
|
41
|
+
```
|
42
|
+
|
43
|
+
This generator will create Rate and RatingCache models and link to your user model.
|
31
44
|
|
32
45
|
### Prepare
|
33
46
|
|
34
|
-
I suppose you have a car model
|
47
|
+
I suppose you have a car model
|
35
48
|
|
36
|
-
|
49
|
+
```
|
50
|
+
rails g model car name:string
|
51
|
+
```
|
37
52
|
|
38
53
|
You should add the letsrate_rateable function with its dimensions option. You can add multiple dimensions.
|
39
54
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
```ruby
|
56
|
+
class Car < ActiveRecord::Base
|
57
|
+
letsrate_rateable "speed", "engine", "price"
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
Then you need to add a call letsrate_rater in the user model.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class User < ActiveRecord::Base
|
65
|
+
letsrate_rater
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
51
69
|
### Using
|
52
70
|
|
53
|
-
There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
|
54
|
-
new rating value from authenticated user.
|
71
|
+
There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
|
72
|
+
new rating value from authenticated user.
|
73
|
+
|
74
|
+
```erb
|
75
|
+
<%# show.html.erb -> /cars/1 %>
|
55
76
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
Price : <%= rating_for @car, "price" %>
|
77
|
+
Speed : <%= rating_for @car, "speed" %>
|
78
|
+
Engine : <%= rating_for @car, "engine" %>
|
79
|
+
Price : <%= rating_for @car, "price" %>
|
80
|
+
```
|
61
81
|
|
62
82
|
If you need to change the star number, you should use star option like below.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
83
|
+
|
84
|
+
```erb
|
85
|
+
Speed : <%= rating_for @car, "speed", :star => 10 %>
|
86
|
+
Speed : <%= rating_for @car, "engine", :star => 7 %>
|
87
|
+
Speed : <%= rating_for @car, "price" %>
|
88
|
+
```
|
89
|
+
|
90
|
+
### Important
|
91
|
+
|
92
|
+
By default rating_for tries to call devise current_user method as the rater instance in the rater_controller.rb file. You can change the current_user method
|
71
93
|
as you will.
|
72
94
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
95
|
+
```ruby
|
96
|
+
#rater_controller.rb
|
97
|
+
|
98
|
+
def create
|
99
|
+
if current_user.present?
|
100
|
+
obj = eval "#{params[:klass]}.find(#{params[:id]})"
|
101
|
+
if params[:dimension].present?
|
102
|
+
obj.rate params[:score].to_i, current_user.id, "#{params[:dimension]}"
|
103
|
+
else
|
104
|
+
obj.rate params[:score].to_i, current_user.id
|
105
|
+
end
|
106
|
+
|
107
|
+
render :json => true
|
108
|
+
else
|
109
|
+
render :json => false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
90
114
|
## Feedback
|
91
|
-
If you find bugs please open a ticket at [github.com/muratguzel/letsrate/issues](github.com/muratguzel/letsrate/issues)
|
92
|
-
|
93
|
-
|
115
|
+
If you find bugs please open a ticket at [https://github.com/muratguzel/letsrate/issues](https://github.com/muratguzel/letsrate/issues)
|
data/Rakefile
CHANGED
data/letsrate.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Letsrate::VERSION
|
8
8
|
s.authors = ["Murat GUZEL"]
|
9
9
|
s.email = ["guzelmurat@gmail.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "http://github.com/muratguzel/letsrate"
|
11
11
|
s.summary = %q{Provides the best solution to add rating functionality to your models.}
|
12
12
|
s.description = %q{Provides the best solution to add rating functionality to your models.}
|
13
13
|
|
data/lib/letsrate/model.rb
CHANGED
data/lib/letsrate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: letsrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides the best solution to add rating functionality to your models.
|
15
15
|
email:
|
@@ -18,14 +18,13 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- .DS_Store
|
22
21
|
- .gitignore
|
22
|
+
- .travis.yml
|
23
23
|
- Gemfile
|
24
24
|
- Gemfile.lock
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- letsrate.gemspec
|
28
|
-
- lib/.DS_Store
|
29
28
|
- lib/generators/letsrate/USAGE
|
30
29
|
- lib/generators/letsrate/letsrate_generator.rb
|
31
30
|
- lib/generators/letsrate/templates/cache_migration.rb
|
@@ -42,7 +41,7 @@ files:
|
|
42
41
|
- lib/letsrate/helpers.rb
|
43
42
|
- lib/letsrate/model.rb
|
44
43
|
- lib/letsrate/version.rb
|
45
|
-
homepage:
|
44
|
+
homepage: http://github.com/muratguzel/letsrate
|
46
45
|
licenses: []
|
47
46
|
post_install_message:
|
48
47
|
rdoc_options: []
|