# How do I use replace\_html without RJS?

**URL:** <https://www.ruby-forum.com/t/how-do-i-use-replace-html-without-rjs/85613>\
**Category:** Rails\
**Created:** [February 14, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/how-do-i-use-replace-html-without-rjs/85613 "2007-02-14T22:16:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [February 14, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/how-do-i-use-replace-html-without-rjs/85613/1 "2007-02-14T22:16:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [February 15, 2007, 2:52pm UTC](https://www.ruby-forum.com/t/how-do-i-use-replace-html-without-rjs/85613/2 "2007-02-15T14:52:10Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [February 15, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/how-do-i-use-replace-html-without-rjs/85613/3 "2007-02-15T17:50:57Z")

</div>

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