module AttachmentsHelper
  def attachment_thumb(attachment)
    file      = attachment.file
    ext       = attachment.file_ext
    dir       = '/images/icons/mime_types'
    url       = file.url(:format => ext)
    thumb_url =
      case ext
      when 'doc' then "#{dir}/application/word.png"
      when 'xls' then "#{dir}/application/excel.png"
      else
        file.url(:thumb)
      end

    link_to(image_tag(thumb_url, :class => 'thumb'), url, :target => '_blank')
  end
end
