can't read multipe text files through a loop in ruby on rails -
i trying read multiple text files @ time. first line making difference between text files while text files name same. using following code can read 1 text file not whole. please me out. here controller code
def index dir.chdir("/home/sbrc/sukanta/opengrok") @f = dir.glob("**/*.txt") = 0 @params = [] while i<@f.length data = io.readlines("/home/sbrc/sukanta/opengrok/"+@f[i]) if data[0] == "jbp prod\n" #@project = data[1] # @cl = data[4] @params = data[1] end i+=1 end end
my view file code , showing undefined method `each' "aruba-i8262-slim-03\n":string "aruba-i8262-slim-03\n 2nd line of text.
<% @params.each |pro| %> <%= pro %> <% end %>
here getting data 1 text file
try change line
@params = data[1]
to
@params << data[1]
or better refactor code bit, like
def index @params = [] dir.glob("/home/sbrc/sukanta/opengrok/*.txt") |file| data = io.readlines(file) @params << [data[1], data[4]].join('@') if data[0] == "jbp prod\n" end end
Comments
Post a Comment