diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb new file mode 100644 index 000000000..1cce0152d --- /dev/null +++ b/app/models/concerns/taggable.rb @@ -0,0 +1,20 @@ +module Taggable + extend ActiveSupport::Concern + + included do + acts_as_taggable + end + + def tag_list_with_limit(limit = nil) + return tags if limit.blank? + + tags.sort{|a,b| b.taggings_count <=> a.taggings_count}[0, limit] + end + + def tags_count_out_of_limit(limit = nil) + return 0 unless limit + + count = tags.size - limit + count < 0 ? 0 : count + end +end diff --git a/app/models/debate.rb b/app/models/debate.rb index 721dfb9cc..4e495281f 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,10 +1,11 @@ require 'numeric' class Debate < ActiveRecord::Base include Flaggable + include Taggable + apply_simple_captcha acts_as_votable - acts_as_taggable acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -84,19 +85,6 @@ class Debate < ActiveRecord::Base super.try :html_safe end - def tag_list_with_limit(limit = nil) - return tags if limit.blank? - - tags.sort{|a,b| b.taggings_count <=> a.taggings_count}[0, limit] - end - - def tags_count_out_of_limit(limit = nil) - return 0 unless limit - - count = tags.size - limit - count < 0 ? 0 : count - end - def after_commented save # updates the hot_score because there is a before_save end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 5d21be8d2..f2693d8ad 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -1,9 +1,10 @@ class Proposal < ActiveRecord::Base include Flaggable + include Taggable + apply_simple_captcha acts_as_votable - acts_as_taggable acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -50,19 +51,6 @@ class Proposal < ActiveRecord::Base super.try :html_safe end - def tag_list_with_limit(limit = nil) - return tags if limit.blank? - - tags.sort{|a,b| b.taggings_count <=> a.taggings_count}[0, limit] - end - - def tags_count_out_of_limit(limit = nil) - return 0 unless limit - - count = tags.size - limit - count < 0 ? 0 : count - end - def description super.try :html_safe end