Class: C80NewsTz::Rubric

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/c80_news_tz/rubric.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.select_all_in_spotsObject

выдать массив рубрик, которые должны выводиться на главной



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/c80_news_tz/rubric.rb', line 27

def self.select_all_in_spots
  s = "
    SELECT
      `c80_news_tz_rubrics`.*,
      `c80_news_tz_spots`.`id` AS `spot_id`
    FROM `c80_news_tz_rubrics`
      INNER JOIN `c80_news_tz_rubrics_spots` ON `c80_news_tz_rubrics_spots`.`rubric_id` = `c80_news_tz_rubrics`.`id`
      INNER JOIN `c80_news_tz_spots` ON `c80_news_tz_spots`.`id` = `c80_news_tz_rubrics_spots`.`spot_id`
    ORDER BY `spot_id`;
  "
  result = self.find_by_sql(s)
  result

end

Instance Method Details

#normalize_friendly_id(input) ⇒ Object



13
14
15
# File 'app/models/c80_news_tz/rubric.rb', line 13

def normalize_friendly_id(input)
  input.to_s.to_slug.normalize(transliterations: :russian).to_s
end

#pubs(lim = nil) ⇒ Object

выдать публикации из этой рубрики



43
44
45
46
47
48
49
# File 'app/models/c80_news_tz/rubric.rb', line 43

def pubs(lim = nil)
  if lim.nil?
    C80NewsTz::Fact.joins(:rubrics).where(:c80_news_tz_rubrics => {:title => self.title})
  else
    C80NewsTz::Fact.joins(:rubrics).where(:c80_news_tz_rubrics => {:title => self.title}).limit(lim)
  end
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'app/models/c80_news_tz/rubric.rb', line 21

def should_generate_new_friendly_id?
  slug.blank?
  # name_changed? || super
end

#slug_candidatesObject



17
18
19
# File 'app/models/c80_news_tz/rubric.rb', line 17

def slug_candidates
  [:title] + Array.new(6) { |index| [:title, index+2] }
end