Class: NewsCategory
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- NewsCategory
- Includes:
- RequiredUniqueName, Toggleable
- Defined in:
- app/models/news_category.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.entity_parameters ⇒ Object
28 29 30 |
# File 'app/models/news_category.rb', line 28 def self.entity_parameters i(name slug priority visible) end |
.page_for_administration ⇒ Object
20 21 22 |
# File 'app/models/news_category.rb', line 20 def self.page_for_administration ordered_by_priority end |
.page_for_visitors ⇒ Object
24 25 26 |
# File 'app/models/news_category.rb', line 24 def self.page_for_visitors visible.ordered_by_priority end |
Instance Method Details
#change_priority(delta) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/news_category.rb', line 42 def change_priority(delta) new_priority = priority + delta adjacent = NewsCategory.find_by(priority: new_priority) if adjacent.is_a?(NewsCategory) && (adjacent.id != id) adjacent.update!(priority: priority) end self.update(priority: new_priority) NewsCategory.ordered_by_priority.map { |e| [e.id, e.priority] }.to_h end |
#full_title ⇒ Object
37 38 39 |
# File 'app/models/news_category.rb', line 37 def full_title name end |
#has_news?(news) ⇒ Boolean
33 34 35 |
# File 'app/models/news_category.rb', line 33 def has_news?(news) news.news_category == self end |