Commit 0a1c2a368fe9272c97bf35f6afa4a7913081849a
1 parent
b109cfa5
Exists in
master
and in
1 other branch
Added aggregate query - number of votes by visitor id to support
geolocation
Showing
2 changed files
with
16 additions
and
2 deletions
Show diff stats
app/controllers/questions_controller.rb
@@ -82,7 +82,21 @@ class QuestionsController < InheritedResources::Base | @@ -82,7 +82,21 @@ class QuestionsController < InheritedResources::Base | ||
82 | # export_type = params[:export_type] | 82 | # export_type = params[:export_type] |
83 | # export_format = params[:export_format] #CSV always now, could expand to xml later | 83 | # export_format = params[:export_format] #CSV always now, could expand to xml later |
84 | end | 84 | end |
85 | - | 85 | + |
86 | + def num_votes_by_visitor_id | ||
87 | + authenticate | ||
88 | + | ||
89 | + @question = current_user.questions.find(params[:id]) | ||
90 | + hash = Vote.count(:conditions => "question_id = #{@question.id}", :group => "voter_id") | ||
91 | + visitor_id_hash = {} | ||
92 | + hash.each do |visitor_id, num_votes| | ||
93 | + visitor = Visitor.find(visitor_id) | ||
94 | + visitor_id_hash[visitor.identifier] = num_votes | ||
95 | + end | ||
96 | + respond_to do |format| | ||
97 | + format.xml{ render :xml => visitor_id_hash.to_xml and return} | ||
98 | + end | ||
99 | + end | ||
86 | 100 | ||
87 | protected | 101 | protected |
88 | def export_votes | 102 | def export_votes |
config/routes.rb
1 | ActionController::Routing::Routes.draw do |map| | 1 | ActionController::Routing::Routes.draw do |map| |
2 | map.resources :clicks | 2 | map.resources :clicks |
3 | - map.resources :questions, :member => { :export => :post, :set_autoactivate_ideas_from_abroad => :put, :activate => :put, :suspend => :put} do |question| | 3 | + map.resources :questions, :member => { :num_votes_by_visitor_id => :get, :export => :post, :set_autoactivate_ideas_from_abroad => :put, :activate => :put, :suspend => :put} do |question| |
4 | question.resources :items | 4 | question.resources :items |
5 | question.resources :prompts, :member => {:vote_left => :post, :vote_right => :post, :skip => :post, :vote => :post}, | 5 | question.resources :prompts, :member => {:vote_left => :post, :vote_right => :post, :skip => :post, :vote => :post}, |
6 | :collection => {:single => :get, :index => :get} | 6 | :collection => {:single => :get, :index => :get} |