How do I use replace_html without RJS?


#1

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’))

defaulthtml

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


#2

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-rails-plugin-0-3

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


#3

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’) })