lib/attachy/models/attachy/viewer.rb in attachy-0.4.0 vs lib/attachy/models/attachy/viewer.rb in attachy-0.4.1
- old
+ new
@@ -10,11 +10,11 @@
@options = options
@view = view
end
def attachments
- [criteria].flatten
+ [criteria].flatten.compact
end
def button_label_options
{ text: '...' }
end
@@ -91,10 +91,12 @@
def hidden_field
@view.hidden_field @object.class.name.downcase, @method, value: value, id: nil
end
def image(file = criteria, t: transform, html: htm)
+ return if file.nil?
+
url = file.url(t)
html = html.reverse_merge(height: t[:height], width: t[:width])
html[:data] = file.transform(t)
@view.image_tag url, html
@@ -142,20 +144,20 @@
@view.content_tag :span, '×'.html_safe, html
end
def value
- [(default? ? [] : criteria)].flatten.to_json
+ default? ? '[]' : attachments.to_json
end
private
def criteria
@criteria ||= @object.send(@method)
end
def default?
- attachments.size == 1 && attachments.last.public_id == Attachy::File.default.public_id
+ attachments.size == 1 && attachments.last.public_id == Attachy::File.default&.public_id
end
def htm(path = [])
@options.dig(*[path, :html].flatten) || {}
end