def first_image(obj, options = {})
      opts = {
        collection: :images,
        method: :image,
        style: :thumbnail,
        default: image_path('noimage.jpg')
      }.merge(options.symbolize_keys!)

      image = obj.send(opts[:collection]).first
      image ? image.send(opts[:method]).url(opts[:style]) : opts[:default]
    end
def first_image(obj, options = {})
      opts = {
        collection: :images,
        method: :image,
        style: :thumbnail,
        default: image_path('noimage.jpg')
      }.merge(options.symbolize_keys!)

      image = obj.send(opts[:collection]).first
      image ? image.send(opts[:method]).url(opts[:style]) : opts[:default]
    end
eg. first_image(@product)