Forum: Ruby on Rails How do I use replace_html without RJS ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
DAN (Guest)
on 2007-02-14 23:16
I'm trying not to use RJS so my html (including images and text) is
preloaded for quicker response.

Example code:

link_to_function('ShowA', replace_html('myshow',
:inline=>'bunchofpreloadedhtmlA'))
link_to_function('ShowB', replace_html('myshow',
:inline=>'bunchofpreloadedhtmlB'))
link_to_function('ShowC', replace_html('myshow',
:inline=>'bunchofpreloadedhtmlC'))

<div id="myshow">
defaulthtml
</div>

This creates an error stating:
undefined method `replace_html' for #<#<Class:0xb6af826c>:0xb6af8244>

If I try to use page. replace_html() I get the error:
undefined local variable or method `page' for
#<#<Class:0xb6afc31c>:0xb6afc2f4>

Another approach to achieve the same interaction might be to create each
link to turn one div CSS display on while turning the other two divs CSS
display values to none (in case they were on).

Any ideas or other approaches appreciated.

Thanks,
DAN
Jason R. (Guest)
on 2007-02-15 15:52
(Received via mailing list)
Um, if you are calling AJAX functions and Javascript response, you
*must*
use RJS. I'll ignore the errors you are having and just answer your
first
issue: trying to get page hits faster, more caching of javascript. For
that,
please check out the Unobtrusive Javascript plugin here:
http://www.ujs4rails.com/2006/8/21/announcing-ujs-...

This puts the javascript for such calls as #link_to_function and
#link_to_remote into a javascript file which can be cached by the
browser.
Give this plugin a try and let us know if you still have issues.

Jason
Alex W. (Guest)
on 2007-02-15 18:50
DAN wrote:
> I'm trying not to use RJS so my html (including images and text) is
> preloaded for quicker response.
>
> Example code:
>
> link_to_function('ShowA', replace_html('myshow',
> :inline=>'bunchofpreloadedhtmlA'))
> link_to_function('ShowB', replace_html('myshow',
> :inline=>'bunchofpreloadedhtmlB'))
> link_to_function('ShowC', replace_html('myshow',
> :inline=>'bunchofpreloadedhtmlC'))

Try

  link_to_function("ShowA",
    render(:update) { |page| page.replace_html('myshow', 'somehtml') })
This topic is locked and can not be replied to.