From b22222a8bb9432e958b980c3d1b6728888cb48d4 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 13 Nov 2015 10:08:50 -0300 Subject: [PATCH] Be prepared for rails4 --- lib/ext/environment.rb | 2 +- lib/gamification_plugin/badge.rb | 2 +- lib/gamification_plugin/dashboard_helper.rb | 2 +- views/gamification/_ranking.html.erb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ext/environment.rb b/lib/ext/environment.rb index 948dc1d..4953b37 100644 --- a/lib/ext/environment.rb +++ b/lib/ext/environment.rb @@ -6,7 +6,7 @@ class Environment has_many :gamification_plugin_organization_badges, :through => :organizations def gamification_plugin_badges - GamificationPlugin::Badge.from("#{gamification_plugin_organization_badges.union(gamification_plugin_environment_badges).to_sql} as #{GamificationPlugin::Badge.table_name}") + GamificationPlugin::Badge.joins('inner join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id]) end end diff --git a/lib/gamification_plugin/badge.rb b/lib/gamification_plugin/badge.rb index 503823a..52b3790 100644 --- a/lib/gamification_plugin/badge.rb +++ b/lib/gamification_plugin/badge.rb @@ -1,4 +1,4 @@ -class GamificationPlugin::Badge < Noosfero::Plugin::ActiveRecord +class GamificationPlugin::Badge < ActiveRecord::Base belongs_to :owner, :polymorphic => true diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index 3726fb4..1100e11 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -27,7 +27,7 @@ module GamificationPlugin::DashboardHelper def ranking(target, from_date=nil, limit=10) # FIXME move these queries to profile model - ranking = Profile.select('profiles.*, sum(num_points) as gamification_points, ROW_NUMBER() OVER(order by sum(num_points) DESC) as gamification_position').joins(:sash => {:scores => :score_points}).where(:type => target.class).order('sum(num_points) DESC').group('profiles.id') + ranking = Profile.select('profiles.*, sum(num_points) as gamification_points, ROW_NUMBER() OVER(order by sum(num_points) DESC) as gamification_position').joins(:sash => {:scores => :score_points}).where(:type => target.class).reorder('sum(num_points) DESC').group('profiles.id') ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? target_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => target.id).first diff --git a/views/gamification/_ranking.html.erb b/views/gamification/_ranking.html.erb index b6afc5f..0b6f8f7 100644 --- a/views/gamification/_ranking.html.erb +++ b/views/gamification/_ranking.html.erb @@ -1,4 +1,4 @@ -<% if ranking.empty? %> +<% if ranking.blank? %>
<%= _('Not enough points for this ranking yet') %>
<% else %>