I am completely new to Rails and I’m trying to make each filetype that is in a directory have its own icon, i can only get it to show one please help? Here is what I have so far.
Controller:
class DocsController < ApplicationController
def port
@files = Dir.glob("public/folder/*")
filetype = [".pdf", ".txt"]
if filetype.include? ".pdf"
@extension = "pdf.png"
elsif filetype.include? ".txt"
@extension = "text.png"
else
@extension = "folder.png"
end
end
end
View:
<% @files.each do |file| %>
<div class="filediv">
<%= image_tag @extension, :size => "150x150" %>
<p><%= file.gsub("public/folder/", "") %></p>
</div>
<% end %>
This is resulting in everything having the pdf icon, can someone tell me what i am doing wrong?
Thanks
I think you need to add helper method
filetype = [“.pdf”, “.txt”]
remove this code.
Now why is always displays a pdf extension
it’s simple
Checkout how include works in array.