Forum: Ruby on Rails Can I use Ajax and Rails to download a file?...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
stuart.hungerford (Guest)
on 2005-11-28 02:17
(Received via mailing list)
Hi,

I'm not sure this is even possible, but has anyone used Ajax
in a Rails environment to download a file from a Rails
application?

I'd like to have a view rendered that says "now downloading
your file foo.baz", waits a second or two then automatically
calls a controller action that uses the send_file() function
to return the file contents.

Hopefully the browser would do the right thing with the bytes
coming back and save them as "foo.baz" and not try to inject
them into a page div?

Any advice much appreciated,


Stu
juca (Guest)
on 2005-11-28 03:33
(Received via mailing list)
You can use the regular redirect... One page shows the message
("downloading file... if download doesn't starts in x seconds, click
here"), and this page have a meta-refresh to a download ling (your
action that uses send_file function, with "attachment" as
content-display).

regards,
juca
stuart.hungerford (Guest)
on 2005-11-28 06:22
(Received via mailing list)
Juraci Krohling C. wrote:

> You can use the regular redirect... One page shows the message
> ("downloading file... if download doesn't starts in x seconds, click
> here"), and this page have a meta-refresh to a download ling (your
> action that uses send_file function, with "attachment" as content-display).

    Thanks for that -- I was kind of hoping I could manage the
    downloading process (including a possibly long waiting period
    until the file is available) with just partial page updates
    via Ajax.

    But, if it's not doable or reasonable to do it that way I'll
    go back to using meta-refresh headers.


Stu
Russ (Guest)
on 2005-11-28 11:49
(Received via mailing list)
I'm working on my second tutorial app (from the Rails book) and hit an
immediate roadblock where my controller "admin_controllor.rb" is not
being found--the message I'm getting is:

Not Found
'/admin' not found
--------------------
WEBrick/1.3.1 (Ruby/1.8.2/2004-12-25) at localhost:3000

I built the rails project and then ran:
  ruby script/generate scaffold Product Admin

Any suggestions for where to start looking?  Maybe some tests to run to
confirm my installation has not been compromised?

Thanks,
russ
This topic is locked and can not be replied to.