Module: Mediumable::ActiveRecordExtensions::InstanceMethods
- Defined in:
- lib/mediumable/active_record_extensions.rb
Instance Method Summary collapse
- #concatenated_media_ids ⇒ Object
- #concatenated_media_ids=(ids) ⇒ Object
- #has_thumb? ⇒ Boolean
- #position_media ⇒ Object
- #thumb ⇒ Object
Instance Method Details
#concatenated_media_ids ⇒ Object
45 46 47 |
# File 'lib/mediumable/active_record_extensions.rb', line 45 def concatenated_media_ids self.media.map(&:id).join(',') end |
#concatenated_media_ids=(ids) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/mediumable/active_record_extensions.rb', line 35 def concatenated_media_ids=(ids) ids = ids.split(",").compact.reject(&:blank?) self.media.each do |medium| medium.mark_for_destruction unless ids.include?(medium.id.to_s) end ms = Medium.find_all_by_id(ids) ms.each{ |m| m.update_attribute(:position, (ids.index(m.id.to_s) + 1)) } self.media = ms end |
#has_thumb? ⇒ Boolean
31 32 33 |
# File 'lib/mediumable/active_record_extensions.rb', line 31 def has_thumb? !thumb.nil? end |
#position_media ⇒ Object
21 22 23 24 25 |
# File 'lib/mediumable/active_record_extensions.rb', line 21 def position_media self.media.each_with_index do |m, i| m.update_attributes :position => i+1 end end |
#thumb ⇒ Object
27 28 29 |
# File 'lib/mediumable/active_record_extensions.rb', line 27 def thumb (@model_images ||= images).first end |