Reputation: 2289
I'm trying to print list of files from current directory. I used
@files = Dir.glob('*')
and in views i'm trying to print using
<%= @files.each {|file| puts "<li>" + file + "</li>"}%>
But instead it prints me just array of filenames, without <li>
tag. WHat am i doing wrong?
Upvotes: 0
Views: 119
Reputation: 6942
in helper
def display_files(dir='*')
list = ""
files = Dir.glob(dir)
@files.each do |file|
list << "<li>#{file}</li>"
end
list
end
In view
Upvotes: 2
Reputation: 9146
use
<% @files.each do |file| %>
<li> <%= file %></li>
<% end %>
You seem to not get the syntax of erb syntax right.
puts
will print the values in logfile not on webpage
Upvotes: 3
Reputation: 13621
As alex said, puts will probably push it to server logs, here's what you can do:
<% @files.each do |file| %>
<li><%= file %></li>
<% end %>
Since you have the = before the @files, you're seeing the string output of an array.
Upvotes: 4