# Replace\_html and page.select behaviour

**URL:** <https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805>\
**Category:** Rails\
**Created:** [June 18, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805 "2008-06-18T19:25:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [June 18, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805/1 "2008-06-18T19:25:58Z")

</div>

Hi,

I want to update a div element selected using its class.  
This is the code I tried in the RJS:

page.replace\_html page.select(’#account div.content’).first, :partial =\>  
‘my\_html’

and also

page.select(’#account div.content’).first.replace\_html :partial =\>  
‘my\_html’

Neither work whereas the following do work:

page.select(’#account div.content’).each do |d|  
page.replace\_html d, :partial =\> ‘boxes/account’  
end

I miss something, can someone explain me?

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [June 18, 2008, 7:27pm UTC](https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805/2 "2008-06-18T19:27:15Z")

</div>

Wrong copy/paste: the partial called is the same for all…

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [June 18, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805/3 "2008-06-18T19:33:48Z")

</div>

Page.select return a collection of object, thus you have to iterate  
over each element before using page.replace\_html

_AurÃ©lien Bottazini_  
[http://www.mycashgarden.com](http://www.mycashgarden.com)

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [June 18, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/replace-html-and-page-select-behaviour/140805/4 "2008-06-18T20:08:53Z")

</div>

On Jun 18, 6:33 pm, Aurélien Bottazini [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Page.select return a collection of object, thus you have to iterate  
> over each element before using page.replace\_html

To be slightly more precise page.select is a magic proxy object. I  
went into it in some detail here:

> **[Conditional RJS explained - Space Vatican](https://www.spacevatican.org/2008/5/26/conditional-rjs-explained/)**
>
> RJS is one of those nifty little things that catches your eye when you first start off using Rails. You very quickly get to add ajax and whizzy …

Fred
