vote_fu 0.0.11 → 2.0.1

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +84 -0
  3. data/README.md +265 -0
  4. data/app/assets/stylesheets/vote_fu/votes.css +391 -0
  5. data/app/channels/vote_fu/application_cable/channel.rb +8 -0
  6. data/app/channels/vote_fu/application_cable/connection.rb +39 -0
  7. data/app/channels/vote_fu/votes_channel.rb +99 -0
  8. data/app/components/vote_fu/like_button_component.rb +136 -0
  9. data/app/components/vote_fu/reaction_bar_component.rb +208 -0
  10. data/app/components/vote_fu/star_rating_component.rb +199 -0
  11. data/app/components/vote_fu/vote_widget_component.rb +181 -0
  12. data/app/controllers/vote_fu/application_controller.rb +49 -0
  13. data/app/controllers/vote_fu/votes_controller.rb +223 -0
  14. data/app/helpers/vote_fu/votes_helper.rb +176 -0
  15. data/app/javascript/vote_fu/channels/consumer.js +3 -0
  16. data/app/javascript/vote_fu/channels/index.js +2 -0
  17. data/app/javascript/vote_fu/channels/votes_channel.js +93 -0
  18. data/app/javascript/vote_fu/controllers/application.js +9 -0
  19. data/app/javascript/vote_fu/controllers/index.js +9 -0
  20. data/app/javascript/vote_fu/controllers/vote_fu_controller.js +148 -0
  21. data/app/javascript/vote_fu/controllers/vote_fu_reactions_controller.js +92 -0
  22. data/app/javascript/vote_fu/controllers/vote_fu_stars_controller.js +77 -0
  23. data/app/models/vote_fu/application_record.rb +7 -0
  24. data/app/models/vote_fu/vote.rb +90 -0
  25. data/app/views/vote_fu/votes/_count.html.erb +29 -0
  26. data/app/views/vote_fu/votes/_downvote_button.html.erb +40 -0
  27. data/app/views/vote_fu/votes/_error.html.erb +9 -0
  28. data/app/views/vote_fu/votes/_like_button.html.erb +67 -0
  29. data/app/views/vote_fu/votes/_upvote_button.html.erb +40 -0
  30. data/app/views/vote_fu/votes/_widget.html.erb +85 -0
  31. data/config/importmap.rb +6 -0
  32. data/config/routes.rb +9 -0
  33. data/lib/generators/vote_fu/install/install_generator.rb +56 -0
  34. data/lib/generators/vote_fu/install/templates/initializer.rb +42 -0
  35. data/lib/generators/vote_fu/install/templates/migration.rb.erb +41 -0
  36. data/lib/generators/vote_fu/migration/migration_generator.rb +29 -0
  37. data/lib/generators/vote_fu/migration/templates/create_vote_fu_votes.rb.erb +40 -0
  38. data/lib/vote_fu/algorithms/hacker_news.rb +54 -0
  39. data/lib/vote_fu/algorithms/reddit_hot.rb +55 -0
  40. data/lib/vote_fu/algorithms/wilson_score.rb +69 -0
  41. data/lib/vote_fu/concerns/karmatic.rb +320 -0
  42. data/lib/vote_fu/concerns/voteable.rb +291 -0
  43. data/lib/vote_fu/concerns/voter.rb +275 -0
  44. data/lib/vote_fu/configuration.rb +53 -0
  45. data/lib/vote_fu/engine.rb +54 -0
  46. data/lib/vote_fu/errors.rb +34 -0
  47. data/lib/vote_fu/version.rb +5 -0
  48. data/lib/vote_fu.rb +22 -9
  49. metadata +217 -60
  50. data/CHANGELOG.markdown +0 -31
  51. data/README.markdown +0 -220
  52. data/examples/routes.rb +0 -7
  53. data/examples/users_controller.rb +0 -76
  54. data/examples/voteable.html.erb +0 -8
  55. data/examples/voteable.rb +0 -10
  56. data/examples/voteables_controller.rb +0 -117
  57. data/examples/votes/_voteable_vote.html.erb +0 -23
  58. data/examples/votes/create.rjs +0 -1
  59. data/examples/votes_controller.rb +0 -110
  60. data/generators/vote_fu/templates/migration.rb +0 -21
  61. data/generators/vote_fu/vote_fu_generator.rb +0 -8
  62. data/init.rb +0 -1
  63. data/lib/acts_as_voteable.rb +0 -114
  64. data/lib/acts_as_voter.rb +0 -75
  65. data/lib/controllers/votes_controller.rb +0 -96
  66. data/lib/has_karma.rb +0 -68
  67. data/lib/models/vote.rb +0 -17
  68. data/rails/init.rb +0 -10
  69. data/test/vote_fu_test.rb +0 -8
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoteFu
4
+ VERSION = "2.0.1"
5
+ end
data/lib/vote_fu.rb CHANGED
@@ -1,9 +1,22 @@
1
- require 'acts_as_voteable'
2
- require 'acts_as_voter'
3
- require 'has_karma'
4
- require 'models/vote.rb'
5
-
6
- ActiveRecord::Base.send(:include, Juixe::Acts::Voteable)
7
- ActiveRecord::Base.send(:include, PeteOnRails::Acts::Voter)
8
- ActiveRecord::Base.send(:include, PeteOnRails::VoteFu::Karma)
9
- RAILS_DEFAULT_LOGGER.info "** vote_fu: initialized properly."
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,236 @@
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.11
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Peter Jackson
8
8
  - Cosmin Radoi
9
9
  - Bence Nagy
10
10
  - Rob Maddox
11
- autorequire:
11
+ - Kandada Boggu
12
+ - Wojciech Wnętrzak
13
+ autorequire:
12
14
  bindir: bin
13
15
  cert_chain: []
14
-
15
- date: 2009-02-11 00:00:00 -05:00
16
- default_executable:
17
- dependencies: []
18
-
19
- description: VoteFu provides the ability to have multiple voting entities on an arbitrary number of models in ActiveRecord.
20
- email: pete@peteonrails.com
16
+ date: 2025-11-30 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: rails
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: '7.2'
25
+ - - "<"
26
+ - !ruby/object:Gem::Version
27
+ version: '9.0'
28
+ type: :runtime
29
+ prerelease: false
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '7.2'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '9.0'
38
+ - !ruby/object:Gem::Dependency
39
+ name: turbo-rails
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '2.0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '2.0'
52
+ - !ruby/object:Gem::Dependency
53
+ name: view_component
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '3.0'
59
+ type: :runtime
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ - !ruby/object:Gem::Dependency
67
+ name: rspec-rails
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '7.0'
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '7.0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: factory_bot_rails
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '6.4'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '6.4'
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.0'
108
+ - !ruby/object:Gem::Dependency
109
+ name: rubocop
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '1.68'
115
+ type: :development
116
+ prerelease: false
117
+ version_requirements: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '1.68'
122
+ - !ruby/object:Gem::Dependency
123
+ name: rubocop-rails
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '2.27'
129
+ type: :development
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '2.27'
136
+ - !ruby/object:Gem::Dependency
137
+ name: rubocop-rspec
138
+ requirement: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '3.2'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '3.2'
150
+ description: |
151
+ VoteFu provides flexible voting capabilities for Rails applications.
152
+ Features include up/down voting, star ratings, scoped voting contexts,
153
+ Wilson Score ranking, Reddit Hot algorithm, counter caches, and
154
+ first-class Hotwire support with Turbo Streams and Stimulus controllers.
155
+ email:
156
+ - pete@peteonrails.com
21
157
  executables: []
22
-
23
158
  extensions: []
24
-
25
159
  extra_rdoc_files: []
26
-
27
- files:
28
- - CHANGELOG.markdown
160
+ files:
161
+ - CHANGELOG.md
29
162
  - MIT-LICENSE
30
- - README.markdown
31
- - generators/vote_fu/vote_fu_generator.rb
32
- - generators/vote_fu/templates/migration.rb
33
- - init.rb
163
+ - README.md
164
+ - app/assets/stylesheets/vote_fu/votes.css
165
+ - app/channels/vote_fu/application_cable/channel.rb
166
+ - app/channels/vote_fu/application_cable/connection.rb
167
+ - app/channels/vote_fu/votes_channel.rb
168
+ - app/components/vote_fu/like_button_component.rb
169
+ - app/components/vote_fu/reaction_bar_component.rb
170
+ - app/components/vote_fu/star_rating_component.rb
171
+ - app/components/vote_fu/vote_widget_component.rb
172
+ - app/controllers/vote_fu/application_controller.rb
173
+ - app/controllers/vote_fu/votes_controller.rb
174
+ - app/helpers/vote_fu/votes_helper.rb
175
+ - app/javascript/vote_fu/channels/consumer.js
176
+ - app/javascript/vote_fu/channels/index.js
177
+ - app/javascript/vote_fu/channels/votes_channel.js
178
+ - app/javascript/vote_fu/controllers/application.js
179
+ - app/javascript/vote_fu/controllers/index.js
180
+ - app/javascript/vote_fu/controllers/vote_fu_controller.js
181
+ - app/javascript/vote_fu/controllers/vote_fu_reactions_controller.js
182
+ - app/javascript/vote_fu/controllers/vote_fu_stars_controller.js
183
+ - app/models/vote_fu/application_record.rb
184
+ - app/models/vote_fu/vote.rb
185
+ - app/views/vote_fu/votes/_count.html.erb
186
+ - app/views/vote_fu/votes/_downvote_button.html.erb
187
+ - app/views/vote_fu/votes/_error.html.erb
188
+ - app/views/vote_fu/votes/_like_button.html.erb
189
+ - app/views/vote_fu/votes/_upvote_button.html.erb
190
+ - app/views/vote_fu/votes/_widget.html.erb
191
+ - config/importmap.rb
192
+ - config/routes.rb
193
+ - lib/generators/vote_fu/install/install_generator.rb
194
+ - lib/generators/vote_fu/install/templates/initializer.rb
195
+ - lib/generators/vote_fu/install/templates/migration.rb.erb
196
+ - lib/generators/vote_fu/migration/migration_generator.rb
197
+ - lib/generators/vote_fu/migration/templates/create_vote_fu_votes.rb.erb
34
198
  - lib/vote_fu.rb
35
- - lib/acts_as_voteable.rb
36
- - lib/acts_as_voter.rb
37
- - lib/has_karma.rb
38
- - lib/models/vote.rb
39
- - lib/controllers/votes_controller.rb
40
- - test/vote_fu_test.rb
41
- - examples/votes_controller.rb
42
- - examples/users_controller.rb
43
- - examples/voteables_controller.rb
44
- - examples/voteable.rb
45
- - examples/voteable.html.erb
46
- - examples/votes/_voteable_vote.html.erb
47
- - examples/votes/create.rjs
48
- - examples/routes.rb
49
- - rails/init.rb
50
- has_rdoc: true
51
- homepage: http://blog.peteonrails.com/vote-fu
52
- licenses: []
53
-
54
- post_install_message:
199
+ - lib/vote_fu/algorithms/hacker_news.rb
200
+ - lib/vote_fu/algorithms/reddit_hot.rb
201
+ - lib/vote_fu/algorithms/wilson_score.rb
202
+ - lib/vote_fu/concerns/karmatic.rb
203
+ - lib/vote_fu/concerns/voteable.rb
204
+ - lib/vote_fu/concerns/voter.rb
205
+ - lib/vote_fu/configuration.rb
206
+ - lib/vote_fu/engine.rb
207
+ - lib/vote_fu/errors.rb
208
+ - lib/vote_fu/version.rb
209
+ homepage: https://votefu.dev
210
+ licenses:
211
+ - MIT
212
+ metadata:
213
+ homepage_uri: https://votefu.dev
214
+ source_code_uri: https://github.com/peteonrails/vote_fu
215
+ changelog_uri: https://github.com/peteonrails/vote_fu/blob/main/CHANGELOG.md
216
+ rubygems_mfa_required: 'true'
217
+ post_install_message:
55
218
  rdoc_options: []
56
-
57
- require_paths:
219
+ require_paths:
58
220
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- requirements:
221
+ required_ruby_version: !ruby/object:Gem::Requirement
222
+ requirements:
61
223
  - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- requirements:
224
+ - !ruby/object:Gem::Version
225
+ version: 3.2.0
226
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
+ requirements:
67
228
  - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
71
231
  requirements: []
72
-
73
- rubyforge_project:
74
- rubygems_version: 1.3.5
75
- signing_key:
76
- specification_version: 3
77
- summary: Voting for ActiveRecord with multiple vote sources and advanced features.
232
+ rubygems_version: 3.5.22
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: Modern voting for Rails 8+ with Turbo, Stimulus, and ActionCable
78
236
  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,7 +0,0 @@
1
-
2
- map.resources :users do |user|
3
- user.resources :votes
4
- user.resources :voteable do |mv|
5
- mv.resources :votes
6
- end
7
- end
@@ -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
@@ -1,8 +0,0 @@
1
- <div id="voteable_<%= @voteable.id %>">
2
-
3
- ..... Show some fields .....
4
-
5
- <div id="votes_<%= @voteable.id %>">
6
- <%= render :partial => "votes/voteable_vote", :locals => {:voteable => @voteable} %>
7
- </div>
8
- </div>
data/examples/voteable.rb DELETED
@@ -1,10 +0,0 @@
1
- class Voteable < ActiveRecord::Base
2
-
3
- belongs_to :user
4
-
5
- acts_as_voteable
6
-
7
- named_scope :descending, :order => "created_at DESC"
8
-
9
-
10
- end