refactors taggable behaviour

This commit is contained in:
rgarcia
2015-09-28 13:33:57 +02:00
parent 2cbbd10c7b
commit 8e42055ece
3 changed files with 24 additions and 28 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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