0

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?

2
  • 1
    Have you ensured you're viewing the raw output, not rendered in the browser's viewport? Commented Sep 6, 2012 at 12:38
  • here is what i see in browser d.pr/i/SLoU Commented Sep 6, 2012 at 12:40

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

2

in helper

def display_files(dir='*')
 list = ""
 files = Dir.glob(dir)
 @files.each do |file|
  list << "<li>#{file}</li>"
 end
list

end

In view

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.