Class: Spina::Attachment

Inherits:
ApplicationRecord show all
Defined in:
app/models/spina/attachment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_destroyObject

Returns the value of attribute _destroy.



7
8
9
# File 'app/models/spina/attachment.rb', line 7

def _destroy
  @_destroy
end

Class Method Details

.order_by_ids(ids) ⇒ Object



27
28
29
30
# File 'app/models/spina/attachment.rb', line 27

def self.order_by_ids(ids)
  sql = sanitize_sql_for_assignment({id: ids})
  order("CASE WHEN #{sql} THEN 0 ELSE 1 END")
end

Instance Method Details

#nameObject



14
15
16
# File 'app/models/spina/attachment.rb', line 14

def name
  file.file.try(:filename)
end

#old_update_attributesObject



18
# File 'app/models/spina/attachment.rb', line 18

alias_method :old_update_attributes, :update_attributes

#update_attributes(attributes) ⇒ Object



19
20
21
22
23
24
25
# File 'app/models/spina/attachment.rb', line 19

def update_attributes(attributes)
  if attributes["_destroy"] == "1" && attributes["file"].blank?
    self.page_part.destroy
  else
    old_update_attributes(attributes)
  end
end