# Rails problem with page.replace

**URL:** <https://www.ruby-forum.com/t/rails-problem-with-page-replace/79292>\
**Category:** Ruby\
**Created:** [December 13, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/rails-problem-with-page-replace/79292 "2006-12-13T22:45:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RaW](https://www.ruby-forum.com/u/RaW)\
**Post date:** [December 13, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/rails-problem-with-page-replace/79292/1 "2006-12-13T22:45:51Z")

</div>

Hi,  
I’m going to add some functionality to my application. I need to replace  
two page’s elements with each other.  
All works fine, but I would like to refresh only changed elements, not  
all on the page.  
I think ajax should hel me but I have a problem with rendering the  
replaced elements.

In the .rjs file I have:

page.replace @photo1.id.to\_s, ‘

# test
’

and this works - it pretty replace appropriate element with given html  
string and also render the page correctly.

But this one, doesnt work at all.  
page.replace @photo1.id.to\_s, :partial =\> “replace2”

In the \_replace2.rhtml I have a temporary text like:

# test

Does someone know what could be the reason of this? Why :partial makes  
that nothing is rendered?

Thanks in advance for any answers.

---

<div class="post-metadata">

**Author:** ![RaW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RaW](https://www.ruby-forum.com/u/RaW)\
**Post date:** [December 14, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/rails-problem-with-page-replace/79292/2 "2006-12-14T21:47:03Z")

</div>

On 12/13/06, RaW [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> page.replace @photo1.id.to\_s, ‘
> 
> # test
> ’  
> Does someone know what could be the reason of this? Why :partial makes  
> that nothing is rendered?
> 
> Thanks in advance for any answers.

Try posting this question on the Ruby on Rails maling list. They’ll be  
able to answer your question much more quickly.

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![RaW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RaW](https://www.ruby-forum.com/u/RaW)\
**Post date:** [December 15, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/rails-problem-with-page-replace/79292/3 "2006-12-15T20:23:50Z")

</div>

Try

page.replace\_html @photo1.id.to\_s, :partial =\> “replace2”

I do not use .rjs files. I use the inline formating.

def action  
if request.xhr?  
render :update do |page|  
page.replace\_html @photo1.id.to\_s, :partial =\>  
“replace2”  
end  
return  
end  
end

Sbeckeriv
