From 27ef9853f4822acef608a2908feb895e90fea4bb Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 11 Feb 2014 18:02:19 -0300 Subject: [PATCH] Don't duplicate themes --- app/controllers/my_profile/themes_controller.rb | 2 +- lib/noosfero/core_ext.rb | 1 + lib/noosfero/core_ext/array.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 lib/noosfero/core_ext/array.rb diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb index f5a4570..81b0f7c 100644 --- a/app/controllers/my_profile/themes_controller.rb +++ b/app/controllers/my_profile/themes_controller.rb @@ -14,7 +14,7 @@ class ThemesController < MyProfileController end def index - @themes = profile.environment.themes + Theme.approved_themes(profile) + @themes = (profile.environment.themes + Theme.approved_themes(profile)).uniq_by{ |t| t.id } @current_theme = profile.theme @layout_templates = LayoutTemplate.all diff --git a/lib/noosfero/core_ext.rb b/lib/noosfero/core_ext.rb index aa0459e..03ef2bb 100644 --- a/lib/noosfero/core_ext.rb +++ b/lib/noosfero/core_ext.rb @@ -1,4 +1,5 @@ require 'noosfero/core_ext/string' require 'noosfero/core_ext/integer' +require 'noosfero/core_ext/array' require 'noosfero/core_ext/object' require 'noosfero/core_ext/active_record' diff --git a/lib/noosfero/core_ext/array.rb b/lib/noosfero/core_ext/array.rb new file mode 100644 index 0000000..0b928ae --- /dev/null +++ b/lib/noosfero/core_ext/array.rb @@ -0,0 +1,9 @@ +class Array + + def uniq_by + hash, array = {}, [] + each { |i| hash[yield(i)] ||= (array << i) } + array + end + +end -- libgit2 0.21.2