[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about displaying the content of a file with Ramaze

Ruby Student

4/20/2009 2:08:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hi all,
I am trying to learn Ramaze and as such I am playing with a very simple
script to display the content of a file on a browser.
My problem begins when I send multiple records to the browser.
Everything is displayed as a long string without end of line. If I edit the
same file with any editor everything looks fine.
I even tried adding the new line character after each line but got the same
results.
Any help will be appreciated.

These are the details:


ruby -v
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mingw32]


ramaze -v
Ramaze Version 2009.03, on ruby 1.9.1 (2009-01-30) [i386-mingw32]

My Mickey Mouse program:

require 'rubygems'
require 'ramaze'

class MainController < Ramaze::Controller
def index
processit
end # index


def processit
line_ary = Array.new
if !File.exist?("F:/$user/ruby/Programs/DejaVou/2009/bmwlist.txt")
return "No List Was Found!"
end

the_list =
File.readlines("F:/$user/ruby/Programs/DejaVou/2009/bmwlist.txt")
the_list.each do |line|
line_ary << line
end
line_ary # Return array of cars to browser
end # processit
end # class
Ramaze.start

The unexpected output:
["328i Convertible 2007 Automatic 2,065 Black Sapphire Metallic $39,995.00
BMW of Honolulu ", "328i Convertible 2007 Automatic 12,303 Platinum Bronze
Metallic $38,995.00 Sonnen BMW ", "328i Convertible 2007 Automatic 16,653
Titanium Silver Metallic $39,997.00 Crown BMW ", "328i Convertible 2007
Automatic 17,531 Titanium Silver Metallic $35,991.00 BMW of Dallas ", "328i
Convertible 2007 Automatic 18,245 Jet Black $38,900.00 Habberstad BMW ",
"328i Convertible 2007 Automatic 18,588 Space Gray Metallic $39,900.00
Medford BMW ", "328i Convertible 2007 Automatic 20,324 Titanium Silver
Metallic $39,995.00 BMW of Riverside ", "328i Convertible 2007 Automatic
20,852 Montego Blue Metallic $37,995.00 Erhard BMW of Farmington Hills ",
"328i Convertible 2007 Automatic 23,669 Monaco Blue Metallic $39,995.00 BMW
of Bridgeport ", "328i Convertible 2007 Automatic 24,036 Platinum Bronze
Metallic $36,970.00 Dreyer & Reinbold, Inc. ", "328i Convertible 2007
Automatic 24,436 Jet Black $39,995.00 Fields BMW - Lakeland ", "328i
Convertible 2007 Automatic 25,455 Crimson Red $39,991.00 Global Imports ",
"328i Convertible 2007 Automatic 29,780 Platinum Bronze Metallic $39,900.00
Vista Motor Company ", "328i Convertible 2007 Automatic 30,121 Titanium
Silver Metallic $36,995.00 Fields BMW - Lakeland ", "328i Convertible 2007
Automatic 30,310 Sparkling Graphite Metallic $38,995.00 Lauderdale BMW of
Fort Lauderdale ", "328i Convertible 2007 Automatic 37,938 Jet Black
$35,988.00 Brecht BMW ", "328i Convertible 2007 Automatic 38,693 Crimson Red
$36,950.00 Rick Hendrick Imports ", "328i Convertible 2007 Automatic 42,062
Crimson Red $33,991.00 Irvine BMW ", "328i Convertible 2008 Automatic 5,821
Titanium Silver Metallic $39,995.00 Century West BMW ", "328i Convertible
2008 Automatic 34,701 Platinum Bronze Metallic $39,991.00 BMW of Houston
North ", "335i Convertible 2007 Automatic 21,070 Monaco Blue Metallic
$39,993.00 Desert BMW of Henderson ", "335i Convertible 2007 Automatic
39,338 Space Gray Metallic $39,933.00 Suntrup West County BMW ", "335i
Convertible 2008 Automatic 43,319 Platinum Bronze Metallic $39,995.00 The
BMW Store "]

Thank you
--
Ruby Student

2 Answers

Ben Lovell

4/20/2009 3:34:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Apr 20, 2009 at 3:08 PM, Ruby Student <ruby.student@gmail.com>wrote:

> Hi all,
> I am trying to learn Ramaze and as such I am playing with a very simple
> script to display the content of a file on a browser.
> My problem begins when I send multiple records to the browser.
> Everything is displayed as a long string without end of line. If I edit the
> same file with any editor everything looks fine.
>
> the_list =
> File.readlines("F:/$user/ruby/Programs/DejaVou/2009/bmwlist.txt")
> the_list.each do |line|
> line_ary << line
>
>
Newline characters are not interpreted by a browser so you need to append a
"<br />" tag to each line. Ideally you should be doing this in a view
instead.

Ben

Ruby Student

4/20/2009 4:48:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Apr 20, 2009 at 11:33 AM, Ben Lovell <benjamin.lovell@gmail.com>wrote:

> On Mon, Apr 20, 2009 at 3:08 PM, Ruby Student <ruby.student@gmail.com
> >wrote:
>
> > Hi all,
> > I am trying to learn Ramaze and as such I am playing with a very simple
> > script to display the content of a file on a browser.
> > My problem begins when I send multiple records to the browser.
> > Everything is displayed as a long string without end of line. If I edit
> the
> > same file with any editor everything looks fine.
> >
> > the_list =
> > File.readlines("F:/$user/ruby/Programs/DejaVou/2009/bmwlist.txt")
> > the_list.each do |line|
> > line_ary << line
> >
> >
> Newline characters are not interpreted by a browser so you need to append a
> "<br />" tag to each line. Ideally you should be doing this in a view
> instead.
>
> Ben
>

Ben,
Thank you for your answer. I'll try using a "view" as you suggested.

--
Ruby Student