How do I go through directories to see if they have files and display only
the directories with files?
Trying to create an Array or something to pass to my view.
The Array/something is supposed to store which directories have files in
them.
Then in my view I want to display only directories with files in them.
def index
@filter = params[:filter]
@type = params[:type]
@content = [] #maybe?
if
directory_path = "public/files/marketing/voip"
directory = Dir.glob("#{directory_path}/#{@filter}/#{@type}")
directory.each do |data| # not sure???
if File.exists?(data) && !File.directory?(data)
# not sure???
@content = Array.new("#{@type}")
end
@view = 'types'
end
#Loop through directories to see if files exist
#If files exist add directory name to @array
end
My view:
<%# Loop through array and create html view for each folder %>
# no idea?
<% @content.each do |o| %>
<% if type.exists %>
<div class="row images">
<div class="span3">
<h5 class="pagination-centered">
<%= link_to (image_tag "/img/folder.jpg", alt: "Buyer's Guides", width:
"75px"), action: "index", filter: @filter, type: "buyers_guides" %>
<%= link_to "Buyer's Guides", action: "index", filter: @filter, type:
"buyers_guides" %>
</h5>
</div>
</div>
I am new to Ruby on Rails, any suggestions?
No comments:
Post a Comment