RJS templates are nifty. They let you put all sorts of fun effects all over your bland html pages without too much work. The link_to_remote function also lets you run scripts before, during, and after an AJAX call is run by using callbacks. There does not seem to be an equivalent method for running an RJS template before or during an action. Rendering it at the end is no problem. One could write a helper function to do all the lifting and use the :before, and :loaded callbacks in the standard way and then let the RJS template handle the rest, but this seems like a poor solution. Anyone have any bright ideas about how to render one RJS template at the beginning of a call and one at the end? (and no, I don't think before_filters will work). _Kevin
on 2006-02-08 07:11
on 2006-02-08 20:04
Actually, the same options you use in the 'old school' remote calls still work with RJS calls. The only option that doesn't work, and seems to break it is the :update option. I'm not sure if you were asking if there was a way to render an RJS template from one of these filters, and that I'm not sure of. Everything else though should work just like before. -Nick On 8 Feb 2006 05:09:03 -0000, Kevin O.
on 2006-02-08 20:41
Nick S. wrote: > Actually, the same options you use in the 'old school' remote calls > still work with RJS calls. The only option that doesn't work, and > seems to break it is the :update option. I'm not sure if you were > asking if there was a way to render an RJS template from one of these > filters, and that I'm not sure of. > > Everything else though should work just like before. > > -Nick > > On 8 Feb 2006 05:09:03 -0000, Kevin O. Yeah, basically I'm looking for a way to have the action control the 'before' callback. The idea of having to specify a :before callback everytime I add an AJAX action and then letting the RJS template handle the :complete seems.... strange and anti-DRY. What I would like to see is some mechanism for allowing AJAX actions to initiate a 'before' RJS template when the action starts, and then render the 'complete' RJS action like it does now. I have a feeling that this is harder than it sounds. If you specify a 'before_filter', then the Ajax listener on the client side just handles the first thing that comes back, and then stops listening. So the final RJS template never gets rendered. Probably the best solution to this is to allow the link_to_remote function to accept an RJS template file for the :before, and :loading callbacks. At least this way the callback functions can be complicated and easily changed without having to be hard-coded. _Kevin
on 2006-02-08 20:51
I think the main problem with this idea is that the before, after, whatever, callbacks all take place on the client side completely in java script. I don't think they were intended for anything more then simple notification type deals. You are still going to have to have the before/after filters in the link no matter what you do I believe. If you have them in the RJS template then it kind of defeats the purpose as you've already made the remote call, or returned from it. The only you might be able to move this stuff to RJS templates is to have the before and after calls actually call an action on some controller that renders it. You would have to do this synchronously though before the main call is fired (I think, it may not matter), but I'm not sure what would be involved in this. Sorry I couldn't be of more help. =\ -Nick