Rails PaperClip Attachments, knowing if there's a image thumbnail? -


i'm using rails 3 paperclip , allow users upload attachments attachment model.

if file image, app generates image previews. if file not, uploads file (no image previews).

now display list of attachments in db. use attachment.attachment(:large) , works fine image attachments, errors (obviously) non-image attachments.

what's way check if it's image attachment or not? if not, i'd display standard static image. suggestions? thanks

this did in view:

<% if !(@attachment.attachment.content_type =~ /^image/).nil? %> <%= image_tag @attachment.attachment.url(:small) %> <%end%> 

this assumes model attachment, , file, called attachment.

so like:

<% if !(@attachment.attachment.content_type =~ /^image/).nil? %> <%= image_tag @attachment.attachment.url(:small) %> <%else%> <%= image_tag "/path/to/image/default.png" %> <%end%> 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -