Triggering the standard Save dialog

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.

I don’t understand. I apologize for being such a novice.

I am also running webrick for testing. Does that make a difference?

On Fri, Nov 19, 2010 at 9:28 AM, Ralph S. [email protected]
wrote:

I have a file, a non-ruby executable or zip file, and I want to trigger
the standard “Save file As” dialog.

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?


Hassan S. ------------------------ [email protected]
twitter: @hassan

On Fri, Nov 19, 2010 at 9:57 AM, Ralph S. [email protected]
wrote:

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.

HS> What’s wrong with putting it somewhere under /public and providing
HS> 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.


Hassan S. ------------------------ [email protected]
twitter: @hassan

Directly accessible how?

What do you recommend as the way to trigger the save dialog?

On Fri, Nov 19, 2010 at 10:26 AM, Ralph S. [email protected]
wrote:

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.


Hassan S. ------------------------ [email protected]
twitter: @hassan

Hassan S. wrote in post #962641:

On Fri, Nov 19, 2010 at 10:26 AM, Ralph S. [email protected]
wrote:

Directly accessible how?

Just provide a link with that URL. This is a basic web operation.

What kind of link? <a …> …
?

On Fri, Nov 19, 2010 at 10:59 AM, Ralph S. [email protected]
wrote:

Just provide a link with that URL. This is a basic web operation.

What kind of link? <a …> …

Yes. A standard web hyperlink.


Hassan S. ------------------------ [email protected]
twitter: @hassan

Hassan,

Friday, November 19, 2010, 10:37:36 AM, you wrote:

HS> On Fri, Nov 19, 2010 at 9:28 AM, Ralph S.
[email protected] wrote:

I have a file, a non-ruby executable or zip file, and I want to trigger
the standard “Save file As” dialog.

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.

HS> What’s wrong with putting it somewhere under /public and providing
HS> that URL?

HS> –
HS> Hassan S. ------------------------ [email protected]
HS> twitter: @hassan

I don’t understand. I apologize for being such a novice.

I am also running webrick for testing. Does that make a difference?


Best regards,
Ralph mailto:[email protected]

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?

On Fri, Nov 19, 2010 at 3:09 PM, Ralph S. [email protected]
wrote:

%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.


Hassan S. ------------------------ [email protected]
twitter: @hassan

Hassan S. wrote in post #962645:

On Fri, Nov 19, 2010 at 10:59 AM, Ralph S. [email protected]
wrote:

Just provide a link with that URL. This is a basic web operation.

What kind of link? <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 S. ------------------------ [email protected]
twitter: @hassan

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

On Fri, Nov 19, 2010 at 5:21 PM, Ralph S. [email protected]
wrote:

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

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.


Hassan S. ------------------------ [email protected]
twitter: @hassan

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.