refactors taggable behaviour
This commit is contained in:
20
app/models/concerns/taggable.rb
Normal file
20
app/models/concerns/taggable.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user