vote_fu 0.0.11 → 2.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 +7 -0
- data/CHANGELOG.md +78 -0
- data/README.md +265 -0
- data/app/assets/stylesheets/vote_fu/votes.css +391 -0
- data/app/channels/vote_fu/application_cable/channel.rb +8 -0
- data/app/channels/vote_fu/application_cable/connection.rb +39 -0
- data/app/channels/vote_fu/votes_channel.rb +99 -0
- data/app/components/vote_fu/like_button_component.rb +136 -0
- data/app/components/vote_fu/reaction_bar_component.rb +208 -0
- data/app/components/vote_fu/star_rating_component.rb +199 -0
- data/app/components/vote_fu/vote_widget_component.rb +181 -0
- data/app/controllers/vote_fu/application_controller.rb +49 -0
- data/app/controllers/vote_fu/votes_controller.rb +223 -0
- data/app/helpers/vote_fu/votes_helper.rb +176 -0
- data/app/javascript/vote_fu/channels/consumer.js +3 -0
- data/app/javascript/vote_fu/channels/index.js +2 -0
- data/app/javascript/vote_fu/channels/votes_channel.js +93 -0
- data/app/javascript/vote_fu/controllers/application.js +9 -0
- data/app/javascript/vote_fu/controllers/index.js +9 -0
- data/app/javascript/vote_fu/controllers/vote_fu_controller.js +148 -0
- data/app/javascript/vote_fu/controllers/vote_fu_reactions_controller.js +92 -0
- data/app/javascript/vote_fu/controllers/vote_fu_stars_controller.js +77 -0
- data/app/models/vote_fu/application_record.rb +7 -0
- data/app/models/vote_fu/vote.rb +90 -0
- data/app/views/vote_fu/votes/_count.html.erb +29 -0
- data/app/views/vote_fu/votes/_downvote_button.html.erb +40 -0
- data/app/views/vote_fu/votes/_error.html.erb +9 -0
- data/app/views/vote_fu/votes/_like_button.html.erb +67 -0
- data/app/views/vote_fu/votes/_upvote_button.html.erb +40 -0
- data/app/views/vote_fu/votes/_widget.html.erb +85 -0
- data/config/importmap.rb +6 -0
- data/config/routes.rb +9 -0
- data/lib/generators/vote_fu/install/install_generator.rb +56 -0
- data/lib/generators/vote_fu/install/templates/initializer.rb +42 -0
- data/lib/generators/vote_fu/install/templates/migration.rb.erb +41 -0
- data/lib/generators/vote_fu/migration/migration_generator.rb +29 -0
- data/lib/generators/vote_fu/migration/templates/create_vote_fu_votes.rb.erb +40 -0
- data/lib/vote_fu/algorithms/hacker_news.rb +54 -0
- data/lib/vote_fu/algorithms/reddit_hot.rb +55 -0
- data/lib/vote_fu/algorithms/wilson_score.rb +69 -0
- data/lib/vote_fu/concerns/karmatic.rb +320 -0
- data/lib/vote_fu/concerns/voteable.rb +291 -0
- data/lib/vote_fu/concerns/voter.rb +275 -0
- data/lib/vote_fu/configuration.rb +53 -0
- data/lib/vote_fu/engine.rb +54 -0
- data/lib/vote_fu/errors.rb +34 -0
- data/lib/vote_fu/version.rb +5 -0
- data/lib/vote_fu.rb +22 -9
- metadata +215 -63
- data/CHANGELOG.markdown +0 -31
- data/README.markdown +0 -220
- data/examples/routes.rb +0 -7
- data/examples/users_controller.rb +0 -76
- data/examples/voteable.html.erb +0 -8
- data/examples/voteable.rb +0 -10
- data/examples/voteables_controller.rb +0 -117
- data/examples/votes/_voteable_vote.html.erb +0 -23
- data/examples/votes/create.rjs +0 -1
- data/examples/votes_controller.rb +0 -110
- data/generators/vote_fu/templates/migration.rb +0 -21
- data/generators/vote_fu/vote_fu_generator.rb +0 -8
- data/init.rb +0 -1
- data/lib/acts_as_voteable.rb +0 -114
- data/lib/acts_as_voter.rb +0 -75
- data/lib/controllers/votes_controller.rb +0 -96
- data/lib/has_karma.rb +0 -68
- data/lib/models/vote.rb +0 -17
- data/rails/init.rb +0 -10
- data/test/vote_fu_test.rb +0 -8
data/lib/vote_fu.rb
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "vote_fu/version"
|
|
4
|
+
require "vote_fu/configuration"
|
|
5
|
+
require "vote_fu/errors"
|
|
6
|
+
require "vote_fu/engine"
|
|
7
|
+
|
|
8
|
+
module VoteFu
|
|
9
|
+
class << self
|
|
10
|
+
def configuration
|
|
11
|
+
@configuration ||= Configuration.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def configure
|
|
15
|
+
yield(configuration)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reset_configuration!
|
|
19
|
+
@configuration = Configuration.new
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,79 +1,231 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vote_fu
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
|
-
authors:
|
|
6
|
+
authors:
|
|
7
7
|
- Peter Jackson
|
|
8
|
-
|
|
9
|
-
- Bence Nagy
|
|
10
|
-
- Rob Maddox
|
|
11
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
12
9
|
bindir: bin
|
|
13
10
|
cert_chain: []
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
date: 2025-11-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.2'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '9.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '7.2'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '9.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: turbo-rails
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: view_component
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rspec-rails
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '7.0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '7.0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: factory_bot_rails
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '6.4'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '6.4'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: sqlite3
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '2.0'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '2.0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: rubocop
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1.68'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '1.68'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: rubocop-rails
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '2.27'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '2.27'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: rubocop-rspec
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - "~>"
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '3.2'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '3.2'
|
|
145
|
+
description: |
|
|
146
|
+
VoteFu provides flexible voting capabilities for Rails applications.
|
|
147
|
+
Features include up/down voting, star ratings, scoped voting contexts,
|
|
148
|
+
Wilson Score ranking, Reddit Hot algorithm, counter caches, and
|
|
149
|
+
first-class Hotwire support with Turbo Streams and Stimulus controllers.
|
|
150
|
+
email:
|
|
151
|
+
- pete@peteonrails.com
|
|
21
152
|
executables: []
|
|
22
|
-
|
|
23
153
|
extensions: []
|
|
24
|
-
|
|
25
154
|
extra_rdoc_files: []
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- CHANGELOG.markdown
|
|
155
|
+
files:
|
|
156
|
+
- CHANGELOG.md
|
|
29
157
|
- MIT-LICENSE
|
|
30
|
-
- README.
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
158
|
+
- README.md
|
|
159
|
+
- app/assets/stylesheets/vote_fu/votes.css
|
|
160
|
+
- app/channels/vote_fu/application_cable/channel.rb
|
|
161
|
+
- app/channels/vote_fu/application_cable/connection.rb
|
|
162
|
+
- app/channels/vote_fu/votes_channel.rb
|
|
163
|
+
- app/components/vote_fu/like_button_component.rb
|
|
164
|
+
- app/components/vote_fu/reaction_bar_component.rb
|
|
165
|
+
- app/components/vote_fu/star_rating_component.rb
|
|
166
|
+
- app/components/vote_fu/vote_widget_component.rb
|
|
167
|
+
- app/controllers/vote_fu/application_controller.rb
|
|
168
|
+
- app/controllers/vote_fu/votes_controller.rb
|
|
169
|
+
- app/helpers/vote_fu/votes_helper.rb
|
|
170
|
+
- app/javascript/vote_fu/channels/consumer.js
|
|
171
|
+
- app/javascript/vote_fu/channels/index.js
|
|
172
|
+
- app/javascript/vote_fu/channels/votes_channel.js
|
|
173
|
+
- app/javascript/vote_fu/controllers/application.js
|
|
174
|
+
- app/javascript/vote_fu/controllers/index.js
|
|
175
|
+
- app/javascript/vote_fu/controllers/vote_fu_controller.js
|
|
176
|
+
- app/javascript/vote_fu/controllers/vote_fu_reactions_controller.js
|
|
177
|
+
- app/javascript/vote_fu/controllers/vote_fu_stars_controller.js
|
|
178
|
+
- app/models/vote_fu/application_record.rb
|
|
179
|
+
- app/models/vote_fu/vote.rb
|
|
180
|
+
- app/views/vote_fu/votes/_count.html.erb
|
|
181
|
+
- app/views/vote_fu/votes/_downvote_button.html.erb
|
|
182
|
+
- app/views/vote_fu/votes/_error.html.erb
|
|
183
|
+
- app/views/vote_fu/votes/_like_button.html.erb
|
|
184
|
+
- app/views/vote_fu/votes/_upvote_button.html.erb
|
|
185
|
+
- app/views/vote_fu/votes/_widget.html.erb
|
|
186
|
+
- config/importmap.rb
|
|
187
|
+
- config/routes.rb
|
|
188
|
+
- lib/generators/vote_fu/install/install_generator.rb
|
|
189
|
+
- lib/generators/vote_fu/install/templates/initializer.rb
|
|
190
|
+
- lib/generators/vote_fu/install/templates/migration.rb.erb
|
|
191
|
+
- lib/generators/vote_fu/migration/migration_generator.rb
|
|
192
|
+
- lib/generators/vote_fu/migration/templates/create_vote_fu_votes.rb.erb
|
|
34
193
|
- lib/vote_fu.rb
|
|
35
|
-
- lib/
|
|
36
|
-
- lib/
|
|
37
|
-
- lib/
|
|
38
|
-
- lib/
|
|
39
|
-
- lib/
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
post_install_message:
|
|
194
|
+
- lib/vote_fu/algorithms/hacker_news.rb
|
|
195
|
+
- lib/vote_fu/algorithms/reddit_hot.rb
|
|
196
|
+
- lib/vote_fu/algorithms/wilson_score.rb
|
|
197
|
+
- lib/vote_fu/concerns/karmatic.rb
|
|
198
|
+
- lib/vote_fu/concerns/voteable.rb
|
|
199
|
+
- lib/vote_fu/concerns/voter.rb
|
|
200
|
+
- lib/vote_fu/configuration.rb
|
|
201
|
+
- lib/vote_fu/engine.rb
|
|
202
|
+
- lib/vote_fu/errors.rb
|
|
203
|
+
- lib/vote_fu/version.rb
|
|
204
|
+
homepage: https://votefu.dev
|
|
205
|
+
licenses:
|
|
206
|
+
- MIT
|
|
207
|
+
metadata:
|
|
208
|
+
homepage_uri: https://votefu.dev
|
|
209
|
+
source_code_uri: https://github.com/peteonrails/vote_fu
|
|
210
|
+
changelog_uri: https://github.com/peteonrails/vote_fu/blob/main/CHANGELOG.md
|
|
211
|
+
rubygems_mfa_required: 'true'
|
|
212
|
+
post_install_message:
|
|
55
213
|
rdoc_options: []
|
|
56
|
-
|
|
57
|
-
require_paths:
|
|
214
|
+
require_paths:
|
|
58
215
|
- lib
|
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
-
requirements:
|
|
216
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
|
+
requirements:
|
|
61
218
|
- - ">="
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
requirements:
|
|
219
|
+
- !ruby/object:Gem::Version
|
|
220
|
+
version: 3.2.0
|
|
221
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
|
+
requirements:
|
|
67
223
|
- - ">="
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
70
|
-
version:
|
|
224
|
+
- !ruby/object:Gem::Version
|
|
225
|
+
version: '0'
|
|
71
226
|
requirements: []
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
specification_version: 3
|
|
77
|
-
summary: Voting for ActiveRecord with multiple vote sources and advanced features.
|
|
227
|
+
rubygems_version: 3.5.22
|
|
228
|
+
signing_key:
|
|
229
|
+
specification_version: 4
|
|
230
|
+
summary: Modern voting for Rails 8+ with Turbo, Stimulus, and ActionCable
|
|
78
231
|
test_files: []
|
|
79
|
-
|
data/CHANGELOG.markdown
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
2009-02-11
|
|
2
|
-
==========
|
|
3
|
-
* Merge in xlash's bugfix for PostgreSQL and his has\_karma patch for multi-model support.
|
|
4
|
-
|
|
5
|
-
2008-12-02
|
|
6
|
-
==========
|
|
7
|
-
* Merge in maddox's README typo fix and his ActiveSupport.Dependency patch
|
|
8
|
-
* Merge in nagybence's updates that make the code usable as a Gem in addition to being a Rails plugin.
|
|
9
|
-
* Thanks for the bugfixes and proofreading, nagybence and maddox!
|
|
10
|
-
* Updated the gemplugin support to be compatible with maddox and nagybence's changes.
|
|
11
|
-
* Added details on the MyQuotable reference application.
|
|
12
|
-
|
|
13
|
-
2008-07-20
|
|
14
|
-
==========
|
|
15
|
-
* Protect against mass assignment misvotes using attr\_accessible
|
|
16
|
-
* Update acts\_as mixins to use self.class.name instead of the deprecated self.type.name
|
|
17
|
-
|
|
18
|
-
2008-07-15
|
|
19
|
-
==========
|
|
20
|
-
* Added examples directory
|
|
21
|
-
* Changed this file to markdown format for GitHub goodness
|
|
22
|
-
* Added a commented out unique index in the migration generator for "one person, one vote"
|
|
23
|
-
* Removed votes\_controller.rb from lib/ and moved to examples
|
|
24
|
-
|
|
25
|
-
2008-07-10
|
|
26
|
-
==========
|
|
27
|
-
|
|
28
|
-
* Added a generator class for the migration.
|
|
29
|
-
* Implemented rails/init.rb
|
|
30
|
-
* Implemented capability to use any model as the initiator of votes.
|
|
31
|
-
* Implemented acts\_as\_voter methods.
|
data/README.markdown
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
vote_fu
|
|
2
|
-
=======
|
|
3
|
-
|
|
4
|
-
Allows an arbitrary number of entites (including Users) to vote on models.
|
|
5
|
-
|
|
6
|
-
### Mixins
|
|
7
|
-
This plugin introduces three mixins to your recipe book:
|
|
8
|
-
|
|
9
|
-
1. **acts\_as\_voteable** : Intended for content objects like Posts, Comments, etc.
|
|
10
|
-
2. **acts\_as\_voter** : Intended for voting entities, like Users.
|
|
11
|
-
3. **has\_karma** : Intended for voting entities, or other objects that own the things you're voting on.
|
|
12
|
-
|
|
13
|
-
### Inspiration
|
|
14
|
-
|
|
15
|
-
This plugin started as an adaptation / update of act\_as\_voteable. It has grown different from that plugin in several ways:
|
|
16
|
-
|
|
17
|
-
1. You can specify the model name that initiates votes.
|
|
18
|
-
2. You can, with a little tuning, have more than one entity type vote on more than one model type.
|
|
19
|
-
3. Adds "acts\_as\_voter" behavior to the initiator of votes.
|
|
20
|
-
4. Introduces some newer Rails features like named\_scope and :polymorphic keywords
|
|
21
|
-
5. Adds "has\_karma" mixin for identifying key content contributors
|
|
22
|
-
|
|
23
|
-
Installation
|
|
24
|
-
============
|
|
25
|
-
Use either the plugin or the gem installation method depending on your preference. If you're not sure, the plugin method is simpler. Whichever you choose, create the migration afterward and run it to create the required model.
|
|
26
|
-
|
|
27
|
-
### Via plugin
|
|
28
|
-
./script/plugin install git://github.com/peteonrails/vote_fu.git
|
|
29
|
-
|
|
30
|
-
### Via gem
|
|
31
|
-
Add the following to your application's environment.rb:
|
|
32
|
-
config.gem "peteonrails-vote_fu", :lib => 'vote_fu', :source => 'http://gems.github.com'
|
|
33
|
-
|
|
34
|
-
Install the gem:
|
|
35
|
-
rake gems:install
|
|
36
|
-
|
|
37
|
-
### Create vote_fu migration
|
|
38
|
-
Create a new rails migration using your new vote_fu generator (Note: "VoteableModel" is the name of the model on which you would like votes to be cast, e.g. Comment):
|
|
39
|
-
./script/generate vote_fu VoteableModel
|
|
40
|
-
|
|
41
|
-
Run the migration:
|
|
42
|
-
rake db:migrate
|
|
43
|
-
|
|
44
|
-
Usage
|
|
45
|
-
=====
|
|
46
|
-
|
|
47
|
-
## Getting Started
|
|
48
|
-
|
|
49
|
-
### Make your ActiveRecord model act as voteable.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class Model < ActiveRecord::Base
|
|
53
|
-
acts_as_voteable
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Make your ActiveRecord model(s) that vote act as voter.
|
|
58
|
-
|
|
59
|
-
class User < ActiveRecord::Base
|
|
60
|
-
acts_as_voter
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
class Robot < ActiveRecord::Base
|
|
64
|
-
acts_as_voter
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
### To cast a vote for a Model you can do the following:
|
|
68
|
-
|
|
69
|
-
#### Shorthand syntax
|
|
70
|
-
voter.vote_for(voteable) # Adds a +1 vote
|
|
71
|
-
voter.vote_against(voteable) # Adds a -1 vote
|
|
72
|
-
voter.vote(voteable, t_or_f) # Adds either +1 or -1 vote true => +1, false => -1
|
|
73
|
-
|
|
74
|
-
#### ActsAsVoteable syntax
|
|
75
|
-
The old acts\_as\_voteable syntax is still supported:
|
|
76
|
-
|
|
77
|
-
vote = Vote.new(:vote => true)
|
|
78
|
-
m = Model.find(params[:id])
|
|
79
|
-
m.votes << vote
|
|
80
|
-
user.votes << vote
|
|
81
|
-
|
|
82
|
-
### Querying votes
|
|
83
|
-
|
|
84
|
-
#### Tallying Votes
|
|
85
|
-
|
|
86
|
-
You can easily retrieve voteable object collections based on the properties of their votes:
|
|
87
|
-
|
|
88
|
-
@items = Item.tally(
|
|
89
|
-
{ :at_least => 1,
|
|
90
|
-
:at_most => 10000,
|
|
91
|
-
:start_at => 2.weeks.ago,
|
|
92
|
-
:end_at => 1.day.ago,
|
|
93
|
-
:limit => 10,
|
|
94
|
-
:order => "items.name desc"
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
This will select the Items with between 1 and 10,000 votes, the votes having been cast within the last two weeks (not including today), then display the 10 last items in an alphabetical list.
|
|
98
|
-
|
|
99
|
-
##### Tally Options:
|
|
100
|
-
:start_at - Restrict the votes to those created after a certain time
|
|
101
|
-
:end_at - Restrict the votes to those created before a certain time
|
|
102
|
-
:conditions - A piece of SQL conditions to add to the query
|
|
103
|
-
:limit - The maximum number of voteables to return
|
|
104
|
-
:order - A piece of SQL to order by. Eg 'votes.count desc' or 'voteable.created_at desc'
|
|
105
|
-
:at_least - Item must have at least X votes
|
|
106
|
-
:at_most - Item may not have more than X votes
|
|
107
|
-
|
|
108
|
-
#### Lower level queries
|
|
109
|
-
ActiveRecord models that act as voteable can be queried for the positive votes, negative votes, and a total vote count by using the votes\_for, votes\_against, and votes\_count methods respectively. Here is an example:
|
|
110
|
-
|
|
111
|
-
positiveVoteCount = m.votes_for
|
|
112
|
-
negativeVoteCount = m.votes_against
|
|
113
|
-
totalVoteCount = m.votes_count
|
|
114
|
-
|
|
115
|
-
And because the Vote Fu plugin will add the has_many votes relationship to your model you can always get all the votes by using the votes property:
|
|
116
|
-
|
|
117
|
-
allVotes = m.votes
|
|
118
|
-
|
|
119
|
-
The mixin also provides these methods:
|
|
120
|
-
|
|
121
|
-
voter.voted_for?(voteable) # True if the voter voted for this object.
|
|
122
|
-
voter.vote_count([true|false|"all"]) # returns the count of +1, -1, or all votes
|
|
123
|
-
|
|
124
|
-
voteable.voted_by?(voter) # True if the voter voted for this object.
|
|
125
|
-
@voters = voteable.voters_who_voted
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
#### Named Scopes
|
|
129
|
-
|
|
130
|
-
The Vote model has several named scopes you can use to find vote details:
|
|
131
|
-
|
|
132
|
-
@pete_votes = Vote.for_voter(pete)
|
|
133
|
-
@post_votes = Vote.for_voteable(post)
|
|
134
|
-
@recent_votes = Vote.recent(1.day.ago)
|
|
135
|
-
@descending_votes = Vote.descending
|
|
136
|
-
|
|
137
|
-
You can chain these together to make interesting queries:
|
|
138
|
-
|
|
139
|
-
# Show all of Pete's recent votes for a certain Post, in descending order (newest first)
|
|
140
|
-
@pete_recent_votes_on_post = Vote.for_voter(pete).for_voteable(post).recent(7.days.ago).descending
|
|
141
|
-
|
|
142
|
-
### Experimental: Voteable Object Owner Karma
|
|
143
|
-
I have just introduced the "has\_karma" mixin to this package. It aims to assign a karma score to the owners of voteable objects. This is designed to allow you to see which users are submitting the most highly voted content. Currently, karma is only "positive". That is, +1 votes add to karma, but -1 votes do not detract from it.
|
|
144
|
-
|
|
145
|
-
class User
|
|
146
|
-
has_many :posts
|
|
147
|
-
has_karma :posts
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
class Post
|
|
151
|
-
acts_as_voteable
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# in your view, you can then do this:
|
|
155
|
-
Karma: <%= @user.karma %>
|
|
156
|
-
|
|
157
|
-
This feature is in alpha, but useful enough that I'm releasing it.
|
|
158
|
-
|
|
159
|
-
### One vote per user!
|
|
160
|
-
If you want to limit your users to a single vote on each item, take a look in lib/vote.rb.
|
|
161
|
-
|
|
162
|
-
# Uncomment this to limit users to a single vote on each item.
|
|
163
|
-
# validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
|
|
164
|
-
|
|
165
|
-
And if you want that enforced at the database level, look in the generated migration for your voteable:
|
|
166
|
-
|
|
167
|
-
# If you want to enfore "One Person, One Vote" rules in the database, uncomment the index below
|
|
168
|
-
# add_index :votes, ["voter_id", "voter_type", "voteable_id", "voteable_type"], :unique => true, :name => "uniq_one_vote_only"
|
|
169
|
-
|
|
170
|
-
### Example Application
|
|
171
|
-
|
|
172
|
-
There is now a reference application available. Due to overwhelming demand for example
|
|
173
|
-
code and kickstart guides, I have open-sourced MyQuotable.com in order to provide an
|
|
174
|
-
easy-to-follow example of how to use VoteFu with RESTful Authentication, JRails, and
|
|
175
|
-
other popular plugins. To get the example code:
|
|
176
|
-
|
|
177
|
-
git clone git://github.com/peteonrails/myquotable.git
|
|
178
|
-
|
|
179
|
-
There will be a screencast coming soon too. Contact me if you want to help.
|
|
180
|
-
|
|
181
|
-
Consideration
|
|
182
|
-
=============
|
|
183
|
-
If you like this software and use it, please consider recommending me on Working With Rails.
|
|
184
|
-
|
|
185
|
-
I don't want donations: a simple up-vote would make my day. My profile is: [http://www.workingwithrails.com/person/12521-peter-jackson][4]
|
|
186
|
-
|
|
187
|
-
To go directly to the "Recommend Me" screen: [http://www.workingwithrails.com/recommendation/new/person/12521-peter-jackson][5]
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
Credits
|
|
191
|
-
=======
|
|
192
|
-
|
|
193
|
-
#### Contributors
|
|
194
|
-
|
|
195
|
-
* Bence Nagy, Budapest, Hungary
|
|
196
|
-
* Jon Maddox, Richmond, Virginia, USA
|
|
197
|
-
|
|
198
|
-
#### Other works
|
|
199
|
-
|
|
200
|
-
[Juixe - The original ActsAsVoteable plugin inspired this code.][1]
|
|
201
|
-
|
|
202
|
-
[Xelipe - This plugin is heavily influenced by Acts As Commentable.][2]
|
|
203
|
-
|
|
204
|
-
[1]: http://www.juixe.com/techknow/index.php/2006/06/24/acts-as-voteable-rails-plugin/
|
|
205
|
-
[2]: http://github.com/jackdempsey/acts_as_commentable/tree/master
|
|
206
|
-
|
|
207
|
-
More
|
|
208
|
-
====
|
|
209
|
-
|
|
210
|
-
Support: [Use my blog for support.][6]
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
[Documentation from the original acts\_as\_voteable plugin][3]
|
|
214
|
-
|
|
215
|
-
[3]: http://www.juixe.com/techknow/index.php/2006/06/24/acts-as-voteable-rails-plugin/
|
|
216
|
-
[4]: http://www.workingwithrails.com/person/12521-peter-jackson
|
|
217
|
-
[5]: http://www.workingwithrails.com/recommendation/new/person/12521-peter-jackson
|
|
218
|
-
[6]: http://blog.peteonrails.com
|
|
219
|
-
|
|
220
|
-
Copyright (c) 2008 Peter Jackson, released under the MIT license
|
data/examples/routes.rb
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# I usually use the user class from restful_authentication as my principle voter class
|
|
2
|
-
# There are generally no changes required to support voting in this controller.
|
|
3
|
-
|
|
4
|
-
class UsersController < ApplicationController
|
|
5
|
-
# Be sure to include AuthenticationSystem in Application Controller instead
|
|
6
|
-
include AuthenticatedSystem
|
|
7
|
-
|
|
8
|
-
# Protect these actions behind an admin login
|
|
9
|
-
before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
|
|
10
|
-
before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge, :show]
|
|
11
|
-
|
|
12
|
-
before_filter :login_required, :only => [:index]
|
|
13
|
-
|
|
14
|
-
# render new.html.erb
|
|
15
|
-
def new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# GET /users/:id
|
|
19
|
-
def show
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def create
|
|
24
|
-
cookies.delete :auth_token
|
|
25
|
-
@user = User.new(params[:user])
|
|
26
|
-
@user.register! if @user.valid?
|
|
27
|
-
if @user.errors.empty?
|
|
28
|
-
self.current_user.forget_me if logged_in?
|
|
29
|
-
cookies.delete :auth_token
|
|
30
|
-
reset_session
|
|
31
|
-
flash[:notice] = "Thanks for signing up!"
|
|
32
|
-
else
|
|
33
|
-
render :action => 'new'
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def activate
|
|
38
|
-
unless params[:activation_code].blank?
|
|
39
|
-
self.current_user = User.find_by_activation_code(params[:activation_code])
|
|
40
|
-
if logged_in? && !current_user.active?
|
|
41
|
-
current_user.activate!
|
|
42
|
-
flash[:notice] = "Signup complete!"
|
|
43
|
-
redirect_back_or_default('/')
|
|
44
|
-
else
|
|
45
|
-
flash[:error] = "Sorry, we couldn't find that activation code. Please cut and paste your activation code into the space at left."
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
# render activate.html.erb
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def suspend
|
|
52
|
-
@user.suspend!
|
|
53
|
-
redirect_to users_path
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def unsuspend
|
|
57
|
-
@user.unsuspend!
|
|
58
|
-
redirect_to users_path
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def destroy
|
|
62
|
-
@user.delete!
|
|
63
|
-
redirect_to users_path
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def purge
|
|
67
|
-
@user.destroy
|
|
68
|
-
redirect_to users_path
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
protected
|
|
72
|
-
def find_user
|
|
73
|
-
@user = User.find(params[:id])
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
data/examples/voteable.html.erb
DELETED