Here's the pertinent part of my cart_controller.rb file:
def checkout
# file creation
File.open('/path/to/file.txt', 'r+') {|cart_file|
cart_file.truncate(0)
for prod in @cart.items
prod.quantity.times do
cart_file.puts(prod.title.to_s)
end
end
}
# offer file for download
send_file('/path/to/file.txt',
:type => 'text/plain',
:disposition => 'attachment')
end
I tried doing cart_file.puts((prod.title.to_s).gsub(/\r\n/,"\n")) up
there, but that didn't really do it. I also tried
cart_file.puts((prod.title.to_s).gsub(/\n/,"\r\n")) (since the file is
created on a Unix server and I need Windows newlines), with no success.
A Ruby regex would be just about perfect, though I'm willing to settle
for executing something on the command-line (provided I can do it from
the webapp) before offering the file for download.
Also, in case it helps, this has only been tested from Firefox 2 on a
Windows XP machine, while the server is a FreeBSD box with Ruby 1.8.6
and Rails 1.2.3, using the built-in WEBrick server.
Thanks a bunch!
Nik Kantar
Web Engineer
MIPS Computation
[EMAIL PROTECTED]
7964-C Arjons Drive
San Diego, Ca 92126-4392
tel +1 858/530.0400 x24
fax +1 858/530.2226
[EMAIL PROTECTED] wrote:
Can you open it up and run it through a ruby regular expression? For
instance:
mystring.gsub(/\r\n/,"\n")
Not sure what your actual control flow is, but maybe at
request time you can create a temp file filtered through
the regexp, then serve out that?
Off the top of my head, untested...
-glenn
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby