rostra 0.1.15 → 0.1.16

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.
@@ -6,7 +6,6 @@ module Rostra
6
6
 
7
7
  def vote
8
8
  rostra_user.vote_on(@answer, params[:vote_direction])
9
-
10
9
  respond_to do |format|
11
10
  format.html { redirect_to question_path(@question, anchor: "rostra_answer_#{@answer.id}") }
12
11
  format.js
@@ -42,7 +42,7 @@ module Rostra
42
42
  end
43
43
 
44
44
  def show
45
- @answers = @question.answers
45
+ @answers = @question.answers.order('votes_count desc')
46
46
  impressionist(@question) # increments page views
47
47
  end
48
48
 
data/app/models/vote.rb CHANGED
@@ -14,4 +14,13 @@ class Vote < ActiveRecord::Base
14
14
  # Comment out the line below to allow multiple votes per user.
15
15
  validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
16
16
 
17
+ after_create :update_counter_cache
18
+ after_destroy :update_counter_cache
19
+
20
+ private
21
+
22
+ def update_counter_cache
23
+ voteable.update_attribute(:votes_count, voteable.plusminus)
24
+ end
25
+
17
26
  end
@@ -1,2 +1,2 @@
1
1
  var selector = "#rostra_answer_<%= @answer.id%> .vote_wrapper";
2
- $(selector).replaceWith('<%= escape_javascript(render(:partial => 'rostra/shared/votes', locals: {resource: @answer})) %>');
2
+ $(selector).replaceWith('<%= escape_javascript(render(partial: 'rostra/shared/votes', locals: {resource: @answer})) %>');
@@ -12,8 +12,8 @@
12
12
 
13
13
  <div class="stats">
14
14
  <div class="vote_count" title="Number of times this question was voted up">
15
- <span class="count"><%= question.plusminus %></span>
16
- <span class="type"><%= question.plusminus.abs == 1 ? 'vote' : 'votes' %></span>
15
+ <span class="count"><%= question.votes_count %></span>
16
+ <span class="type"><%= question.votes_count.abs == 1 ? 'vote' : 'votes' %></span>
17
17
  </div>
18
18
  <div class="answer_count" title="Number of times this question was answered">
19
19
  <span class="count"><%= question.answer_count %></span>
@@ -1,2 +1,2 @@
1
- var selector = "#rostra_question_<%= @question.id%> .vote_wrapper";
1
+ var selector = "#rostra_question_<%= @question.id %> .vote_wrapper";
2
2
  $(selector).replaceWith('<%= escape_javascript(render partial: 'rostra/shared/votes', locals: { resource: @question }) %>');
@@ -1,6 +1,6 @@
1
1
  <div class="vote_wrapper">
2
2
  <%= link_to_vote(:up, resource) %>
3
- <div class="count"><%= resource.plusminus %></div>
3
+ <div class="count"><%= resource.votes_count %></div>
4
4
  <%= link_to_vote(:down, resource) %>
5
5
  </div>
6
6
 
@@ -0,0 +1,5 @@
1
+ class AddVotesCountToRostraAnswers < ActiveRecord::Migration
2
+ def change
3
+ add_column :rostra_answers, :votes_count, :integer, default: 0
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddVotesCountToRostraQuestions < ActiveRecord::Migration
2
+ def change
3
+ add_column :rostra_questions, :votes_count, :integer, default: 0
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Rostra
2
- VERSION = "0.1.15"
2
+ VERSION = "0.1.16"
3
3
  end
data/lib/rostra.rb CHANGED
@@ -61,6 +61,7 @@ module Rostra
61
61
  else
62
62
  vote(resource, {:exclusive => true, :direction => direction})
63
63
  end
64
+ resource.reload
64
65
  end
65
66
 
66
67
  # Check if the user is following a given question
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rostra
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.15
5
+ version: 0.1.16
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cory Schires
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-02 00:00:00 Z
13
+ date: 2011-11-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -556,6 +556,8 @@ files:
556
556
  - db/migrate/20111019162723_create_rostra_question_followings.rb
557
557
  - db/migrate/20111024223022_add_send_email_notifications_to_question_followings.rb
558
558
  - db/migrate/20111029214642_add_impressions_count_to_questions.rb
559
+ - db/migrate/20111106162542_add_votes_count_to_rostra_answers.rb
560
+ - db/migrate/20111106164824_add_votes_count_to_rostra_questions.rb
559
561
  - lib/generators/rostra/install_generator.rb
560
562
  - lib/generators/rostra/templates/app/helpers/rostra/application_helper.rb
561
563
  - lib/generators/rostra/templates/config/initializers/rostra.rb