Module: TbCommerce::ApplicationHelper

Defined in:
app/helpers/tb_commerce/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#imageable_tag(imageable, params = { size: :tb_commerce_medium }) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/tb_commerce/application_helper.rb', line 2

def imageable_tag(imageable, params = { size: :tb_commerce_medium })
  url = ""
  if !imageable
    #write a default image
    return
  end

  if imageable.is_a?(TbCommerce::Image)
    url = imageable.image.url(params[:size])
  else imageable.is_a?(TbCommerce::Product) || imageable.is_a?(TbCommerce::Category) || imageable.is_a?(TbCommerce::ProductSku)
    featured_image = imageable.featured_image
    if featured_image
      url = featured_image.image.url(params[:size])
    else
      url = imageable.images.first().image.url(params[:size])
    end
  end

  image_tag(url)
end