Formatting issue

I have a text file that has data in it which is perfectly formatted the way I want it. I have the following code in my controller to open the file and read each line into an array which I then call from my view. The problem is, I completely loose the formatting the way I'm doing it:

<%= ... %> basically just calls to_s on whatever the expression in there evaluates to, and to_s on an Array is just the concatenation of to_s called on everything in it. If you just want to display data from the file, why not use @my_data = File.read(...) ?

Fred

Here is the data, if you put it in a file and then tell Rails to read it, please see if you can get it to display in the exact same format in Rails. When I do it, all my columns don't line up:

Mod Ports Card Type Model Serial No. --- ----- -------------------------------------- ------------------

They don't line up in this email, either :slight_smile:

Are you trying to display this in PRE tags or equivalent CSS with a monospace font?

Your display would probably be more robust if you parsed the file contents and put it in an actual HTML table, though.

FWIW,

Hassan Schroeder wrote:

They don't line up in this email, either :slight_smile:

...hehe....I know, I'm sorry that wasn't much of a help :slight_smile:

Are you trying to display this in PRE tags or equivalent CSS with a monospace font?

..good call on this one though, I added PRE tags on my index.rhtml and the data is looking the way I want it...which is great news.

I am still a bit baffled as to why I have to write the data to a file first, then open the file and put it in PRE tags as opposed to using PUTS statements in my original script and assigning that to a variable which gets called by my index page which still causes the format to be skewed.

--- my_data.rb code: data.each do |line|   a.write(line) #--this writes to my_data.dat   puts line #--this puts the same data to STDOUT end --- controller code: def index   @my_data = `/usr/bin/my_data.rb` #this causes data to be skewed   #@my_data = File.open("/usr/bin/my_data.dat").read #this works end --- index.rthml code: <pre><%= simple_format @my_data %></pre>

puts always appends a carriage return whereas write doesn't. if you
changed it to STDOUT.write(line) it should be the same

Fred

STDOUT.write(line) fixed the problem....thanks again for the help!

Frederick Cheung wrote: