11155
(-- --)
November 19, 2010, 5:28pm
1
I have a file, a non-ruby executable or zip file, and I want to trigger
the standard "Save file As" dialog.
What is the RoR way to do this?
- - - -
I have scoured the net and the only think I can come up with is some
Javascript that gets triggered when the user clicks on an image.
function my_onclick()
{
alert('This is an alert');
var url='/LaunchBrowser.zip';
// window.location = url
window.open(url,'Download');
};
The javascript runs but it opens a new browser tab/window with the
following error:
Routing Error
No route matches "/LaunchBrowser.zip" with {:method=>:get}
- - - -
Surely there must be a simple way to enable the user to download a file
that they want to get and that I want to give them.
hassan
(Hassan Schroeder)
November 19, 2010, 5:37pm
2
What's wrong with putting it somewhere under /public and providing
that URL?
Re[2]: [Rails] Triggering the standard Save dialog
Hassan,
Friday, November 19, 2010, 10:37:36 AM, you wrote:
11155
(-- --)
November 19, 2010, 5:59pm
4
I don't understand. I apologize for being such a novice.
I am also running webrick for testing. Does that make a difference?
hassan
(Hassan Schroeder)
November 19, 2010, 6:03pm
5
Surely there must be a simple way to enable the user to download a file
that they want to get and that I want to give them.
> What's wrong with putting it somewhere under /public and providing
> that URL?
I don't understand. I apologize for being such a novice.
Files under RAILS_ROOT/public are directly accessible -- like your
app's javascript, css, or image files.
I am also running webrick for testing. Does that make a difference?
Nope.
11155
(-- --)
November 19, 2010, 6:26pm
6
Directly accessible how?
What do you recommend as the way to trigger the save dialog?
hassan
(Hassan Schroeder)
November 19, 2010, 6:32pm
7
Directly accessible how?
Just provide a link with that URL. This is a basic web operation.
What do you recommend as the way to trigger the save dialog?
If the file has a .zip or .exe extension, it should be automatic.
11155
(-- --)
November 19, 2010, 6:59pm
8
Hassan Schroeder wrote in post #962641:
hassan
(Hassan Schroeder)
November 19, 2010, 7:07pm
9
Yes. A standard web hyperlink.
11155
(-- --)
November 19, 2010, 8:16pm
10
Hassan Schroeder wrote in post #962645:
Just provide a link with that URL. This is a basic web operation.
What kind of link? <a ...> ... </a>
Yes. A standard web hyperlink.
In other words: there's nothing magical about HTML files or images. The
browser is smart enough to do the right thing with any content you
provide -- even if that "right thing" is saving for use with another
application.
The reason that it's so hard to explicitly trigger a Save dialog in the
browser is that there's never any need to do so!
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Best,
11155
(-- --)
November 19, 2010, 11:09pm
11
I am so frustrated. My HAML code is
%div{'id' => becca_chap_1_human_img_div}
%a{'id' => download_file_a, 'href' => '/public/LaunchBrowser.zip'}
= image_tag('PhotosOfBecca.png', :'id' => becca_chap_1_human_img)
The HAML parses correctly ...
Yet when I click on the image I get a routing error
Routing Error
No route matches "/public/LaunchBrowser.zip" with {:method=>:get}
What am I doing wrong?
hassan
(Hassan Schroeder)
November 19, 2010, 11:28pm
12
%a\{'id' => download\_file\_a, 'href' => '/public/LaunchBrowser\.zip'\}
You could look at your css/js/image references as examples, as I
said previously...
No route matches "/public/LaunchBrowser.zip" with {:method=>:get}
.. which would show you that '/public' is *not* part of the URL.
11155
(-- --)
November 20, 2010, 1:21am
13
I'm sorry, Hassan, I still don't get it.
When I make that link, i.e.
/public/LaunchBrowser.zip
why is the link going through rails routing?
If I make the link
LaunchBrowser.zip
then rails seems to want the link to be
http://localhost:3000/marketing/LaunchBrowser.zip
which makes sense because the the file setting up the link to
LaunchBrowser.zip is
F:\Ralph-Rails-Apps\UltraDedup\app\views\marketing\demodownload.haml
Again, sorry to be so dense.
hassan
(Hassan Schroeder)
November 20, 2010, 2:22am
14
Because you haven't made it "/LaunchBrowser.zip".
Have you *looked* at any of your standard css/js/image file URLs
that currently live under RAILS_ROOT/public? Pick one. Look at the
generated markup for that. If that doesn't answer your questions, ask
again, pasting it in as an example.