我需要知道目录是否为空,以免显示。
尝试存储:如果目录有文件;然后我会在视图中调用它。
def index
@filter = params[:filter]
@type = params[:type]
@content = []
if @filter
directory_path = "public/files/marketing/voip"
directory = Dir.glob("#{directory_path}/#{@filter}/#{@type}")
directory.each do |data|
if File.exists?(data) && !File.directory?(data)
@content = Array.new("#{@type}")
end
@view = 'types'
end
end
我不确定如何存储信息,这里我只想存储空目录的@type。
然后在视图中调用@content 以显示具有我存储的@type 的目录。