# NEWBIE: replace\_html not working as I expected HELP!

**URL:** <https://www.ruby-forum.com/t/newbie-replace-html-not-working-as-i-expected-help/124249>\
**Category:** Rails\
**Created:** [December 27, 2007, 3:03am UTC](https://www.ruby-forum.com/t/newbie-replace-html-not-working-as-i-expected-help/124249 "2007-12-27T03:03:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [December 27, 2007, 3:03am UTC](https://www.ruby-forum.com/t/newbie-replace-html-not-working-as-i-expected-help/124249/1 "2007-12-27T03:03:47Z")

</div>

I was hoping the following code would generate a new turing everytime  
it was click. But it renders everything the first time the page is  
rendered and replaces the image once… but also has already set to  
session[turing] to the last call to createturing… so the first image  
and session[turing] don;t match!!! I thought moving to a partial  
would hold off the execution of the partial until the link was  
clicked… guess not!!!

how should i implement this?

\<%= render(:partial =\> "createturing" ) %\>
\<%= link\_to\_function 'refresh' do |page| page.replace\_html 'turing', render(:partial =\> 'createturing') end %\>

---

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [December 27, 2007, 3:20am UTC](https://www.ruby-forum.com/t/newbie-replace-html-not-working-as-i-expected-help/124249/2 "2007-12-27T03:20:10Z")

</div>

On 27 Dec 2007, at 02:03, spokra wrote:

> I was hoping the following code would generate a new turing everytime  
> it was click. But it renders everything the first time the page is  
> rendered and replaces the image once… but also has already set to  
> session[turing] to the last call to createturing… so the first image  
> and session[turing] don;t match!!! I thought moving to a partial  
> would hold off the execution of the partial until the link was  
> clicked… guess not!!!

No as you found out, this is all evaluated in one go (How could it be  
otherwise since rendering the partial can only happen serverside?)

> how should i implement this?
> 
> \<%= render(:partial =\> "createturing" ) %\>
> \<%= link\_to\_function 'refresh' do |page| page.replace\_html 'turing', render(:partial =\> 'createturing') end %\>

You can use link\_to\_remote to make an ajax call.

Fred

---

<div class="post-metadata">

**Author:** ![spokra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spokra](https://www.ruby-forum.com/u/spokra)\
**Post date:** [December 27, 2007, 3:51am UTC](https://www.ruby-forum.com/t/newbie-replace-html-not-working-as-i-expected-help/124249/3 "2007-12-27T03:51:09Z")

</div>

Steep learing curve but I’m starting to get it!!!

Thanks that did the quick and after getting your pointer it only took  
me a few minutes to implement it!! thats rapid!!

On Dec 26, 6:19 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
