Class: Helpdesk::Faq

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/helpdesk/faq.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collectionObject



41
42
43
44
45
46
47
48
# File 'app/models/helpdesk/faq.rb', line 41

def self.collection
  arr = []
  roots.each do |faq|
    arr << faq
    arr << faq.descendants
  end
  return arr.flatten
end

.search(query, page = 1) ⇒ Object



29
30
31
32
33
34
35
# File 'app/models/helpdesk/faq.rb', line 29

def self.search(query, page=1)
  query = "%#{query}%"
  arel_faqs_t = Arel::Table.new(:helpdesk_faq_translations)
  name_match = arel_faqs_t[:title].matches(query)
  postal_match = arel_faqs_t[:text].matches(query)
  with_translations.active.where(name_match.or(postal_match)).page(page)
end

Instance Method Details

#anchorObject



37
38
39
# File 'app/models/helpdesk/faq.rb', line 37

def anchor
  "##{to_param}"
end

#name_with_depthObject



13
14
15
# File 'app/models/helpdesk/faq.rb', line 13

def name_with_depth
  "#{"&nbsp;&nbsp;&nbsp;&nbsp;"*depth}\\_ #{title}".html_safe
end

#nnameObject



21
22
23
24
25
26
27
# File 'app/models/helpdesk/faq.rb', line 21

def nname
  if parent
    "#{parent.nname}--#{title.parameterize}"
  else
    "#{title.parameterize}"
  end
end

#to_paramObject



17
18
19
# File 'app/models/helpdesk/faq.rb', line 17

def to_param
  id ? "#{id}-#{nname}" : nil
end