Class: Photo
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Photo
- Defined in:
- app/models/photo.rb
Constant Summary collapse
- PER_PAGE =
20
Class Method Summary collapse
- .creation_parameters ⇒ Object
- .entity_parameters ⇒ Object
- .page_for_administration(page = 1) ⇒ Object
- .page_for_visitors(page = 1) ⇒ Object
Instance Method Summary collapse
Class Method Details
.creation_parameters ⇒ Object
30 31 32 |
# File 'app/models/photo.rb', line 30 def self.creation_parameters entity_parameters + %i(album_id) end |
.entity_parameters ⇒ Object
26 27 28 |
# File 'app/models/photo.rb', line 26 def self.entity_parameters %i(image name description) end |
.page_for_administration(page = 1) ⇒ Object
17 18 19 |
# File 'app/models/photo.rb', line 17 def self.page_for_administration(page = 1) ordered_by_priority.page(page).per(PER_PAGE) end |
.page_for_visitors(page = 1) ⇒ Object
22 23 24 |
# File 'app/models/photo.rb', line 22 def self.page_for_visitors(page = 1) ordered_by_priority.page(page).per(PER_PAGE) end |
Instance Method Details
#change_priority(delta) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/photo.rb', line 35 def change_priority(delta) new_priority = priority + delta adjacent = Photo.siblings(self).find_by(priority: new_priority) if adjacent.is_a?(Photo) && (adjacent.id != id) adjacent.update!(priority: priority) end update(priority: new_priority) Photo.siblings(self).map { |e| [e.id, e.priority] }.to_h end |