File icon giver/getter/whatever
It gets the file extension then looks up that extension in a dir full of files named extension.png
if none is found, unknown.png is used
1 2 <% 3 extension = File.extname(attachment.filename).gsub(/\./, "") 4 # get a file icon 5 icon_path = nil 6 Dir.entries("#{RAILS_ROOT}/public/images/filetypes").each do |entry| 7 entry_extension = File.extname(entry) 8 if entry.gsub(entry_extension, "") === extension 9 icon_path = "/images/filetypes/" + entry 10 break 11 end 12 end 13 icon_path = "/images/filetypes/unknown.png" if icon_path.nil? 14 %> 15 <%= image_tag icon_path %> 16 <span class="attachment_name"><%= attachment.filename %></span><br />