intermingle RJS partial rendering and raw javascript
wrap partial rendering in javascript
What I need is the ability to seamlessly send the contents of a partial to the client using the convenience of RJS, but wrapped inside a hand-written javascript condition (if some element exists, then update an element with this partial).
# RJS template page << "if ('some_element_exists') {// page.replace_html using a partial}"
The challenge is to interlace a basic javascript condition with the ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods such as replace_html, hide, show, select, etc.
Viewing the source for replace_html, you see that it simply wraps the call GeneratorMethod, passing it Element.update, which is the prototype js function doing the client-side work. Additionally, it calls render to pull the html from the partial, which is exactly what I need. Thus, I now have exactly what I need to intermingle my javascript condition with the simplicity of RJS methods calls.
# RJS template page << "if ($('element_id')) { $('element_id').update(#{render :partial => 'my_partial_marshal'})};"
Notice that I remove replace_html for its javascript counterpart, Element.update. What's left is primarily raw javascript being appended to the page object but with the convenience of Rails' partial rendering.
Posted by Luke on Sunday, March 16, 2008
Comments (1)
QJzBCp <a href=”http://gchadtsaflvu.com/”>gchadtsaflvu</a>, [url=http://gwcsyzqxktxo.com/]gwcsyzqxktxo[/url], [link=http://qsakwqfepvqz.com/]qsakwqfepvqz[/link], http://nlizhclrcwog.com/

