Module: OmgImage::ApplicationHelper

Includes:
OmgHelper
Defined in:
app/helpers/omg_image/application_helper.rb

Constant Summary

Constants included from OmgHelper

OmgHelper::COLORS

Instance Method Summary collapse

Methods included from OmgHelper

#assigned_color

Instance Method Details

#omg_image_preview(template, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/omg_image/application_helper.rb', line 10

def omg_image_preview(template, options)
  options        ||= {}
  options[:size] ||= '800,400'
  options[:key]  ||= options.to_s

  image = OmgImage::Image.find_by(key: options[:key])
  if image && !image.file.attached?
    image.destroy
    image = nil
  end

  file = image&.file || create_screenshot(template, options)

  url_for(file) if file
end