Forum: Ruby on Rails link_to with callbacks ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-03-22 18:25
(Received via mailing list)
I've got an image link that's currently using link_to_remote.  The link
calls a method that creates a file and completes with render :nothing =>
true.   I'm using the :loading and :complete callbacks on
link_to_remote.   On :loading I call a function that renders a
'disabled' image while the file's being created.  When the method
completes, I use the :complete callback to call another function that
opens a popup containing the file that got created and then renders the
original 'enabled' image.

The above works fine except for one thing.  AFAIK, because it's being
loaded by as opposed to being sent to the browser, the file that gets
rendered in the popup has to exist in the 'public' (or some other
externally visible) directory.  I need the file to _not_ be visible

The first solution I tried was to eliminate the popup (too many folks
have popups disabled anyway) and change the 'render :nothing => true' to
a 'send_file'.  That sends the file to the browser (I can see the file
content in Firebug) but, I guess since the browser is expecting a JS
response, it doesn't do anything with it.  Anybody know a way to send a
file using RJS so I can get the 'view or save' dialog box?

The second solution I tried was to change the link_to_remote to link_to.
That lets me send the file from a non-externally-visible location, which
solves that problem, but AFAIK link_to doesn't support the callbacks.  I
guess I could use the :onclick to trigger rendering the 'disabled'
image, but can't figure out how I'd be able to change back to the
'enabled' image once the file was received.  Any thoughts on how I could
make this work?

Any thoughts on other approaches I might try would be greatly
appreciated.  Like, is there maybe some way to use routes to have the'title', 'location/filename') being executed in the browser
to open the popup and retrieve the file be intercepted by Rails and
mapped to a hidden location?

This topic is locked and can not be replied to.