Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 913 Bytes
1 | class PostVote < ActiveRecord::Base |
2 | belongs_to :post |
3 | belongs_to :voter, :class_name => 'User', :foreign_key => 'voter_id' |
4 | |
5 | include ErrorRaising |
6 | |
7 | MAX_VALUE = 10 |
8 | MIN_VALUE = -10 |
9 | |
10 | # Calculate and return the user rating for this post. |
11 | def self.rate(post) |
12 | query_result = self.find_by_sql <<-EOL |
13 | SELECT SUM(value) AS total_score, COUNT(value) AS number_of_votes |
14 | FROM post_votes |
15 | WHERE post_id = '#{post.id}' |
16 | GROUP BY post_id |
17 | EOL |
18 | first_row = query_result.first |
19 | if first_row.nil? |
20 | rating = 0 |
21 | else |
22 | rating = first_row.total_score.to_f / first_row.number_of_votes.to_f |
23 | end |
24 | rating |
25 | end |
26 | |
27 | protected |
28 | def before_save |
29 | if self.post.user_id == self.voter.id |
30 | raise ArgumentError, "cannot vote own posts" |
31 | end |
32 | |
33 | unless (MIN_VALUE..MAX_VALUE).member? self.value |
34 | raise ArgumentError, "value out of range" |
35 | end |
36 | end |
37 | end |