I have a model connected to a log, so I’m beginning to build ways to use that info with the model and pass it around elsewhere.
this method:
def read_log
counter = 1
f = File.open(self.log_file_path, 'r')
while (line = f.gets)
puts "#{counter}: #{line}"
counter = counter + 1
end
end
works, and dumps the log to the command line but ends with nil, so it reads it out to stdout but when calling that I get nothing. How can I read the contents into a more useful format? I need to read this into a controller variable for a template within rails on a webpage. It is basic, but something I haven’t done yet.
Now
contentscontains… the contents. Not sure what “useful” means in your context, but you can do things like split on newline to get each line.You can also create an enumerator via
f.lines, whether or not that’s more useful, not sure.