# AJAX - weird display

**URL:** <https://www.ruby-forum.com/t/ajax-weird-display/87120>\
**Category:** Rails\
**Created:** [February 28, 2007, 11:35am UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120 "2007-02-28T11:35:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [February 28, 2007, 11:35am UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/1 "2007-02-28T11:35:52Z")

</div>

Hi,

I have a tabular (it’s a form actually) with text\_fields and buttons.  
I wanted to diplay a particular row when a button is set to ‘yes’.  
Everything’s working fine except, that my new row is diplayed at the top  
of the array and not where I want. I can do page.add\_html/delete and  
specify bottom, but I don’t understand why my snippet doesn’t work.

Any idea?

Used to programming in Ruby? \<%= radio\_button :form,:ruby,:yes, :onclick =\> remote\_function(:url =\> {:controller =\> '/my\_controler', :action =\>'my\_action', :ruby =\> 'yes'}, :method =\> :post)%\> \<%= radio\_button :form,:ruby,:yes, :onclick =\> remote\_function(:url =\> {:controller =\> '/my\_controler', :action =\>'my\_action', :ruby =\> 'no'}, :method =\> :post)%\>
 \<%= render :partial =\> 'yes' %\>

And the partial yes:  
\<% if @ruby -%\>

bla bla bla ../.. \<% end -%\>

With the rjs  
page.replace\_html ‘my\_id’, :partial =\> ‘yes’

Thanks!

–  
,========================.  
| Pierre-Alexandre M. |  
| email : removed\_email\_address@domain.invalid |  
`========================’

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [February 28, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/2 "2007-02-28T17:07:46Z")

</div>

Pierre-Alexandre M. wrote:

> Hi,
> 
> I have a tabular (it’s a form actually) with text\_fields and buttons.  
> I wanted to diplay a particular row when a button is set to ‘yes’.  
> Everything’s working fine except, that my new row is diplayed at the top  
> of the array and not where I want. I can do page.add\_html/delete and  
> specify bottom, but I don’t understand why my snippet doesn’t work.

Hi Pierre,  
This looks perfectly correct to me. I do something similar but with an  
unordered list, and div’s around each of the

- lines. replace\_html  
cleanly replaces just the line I want to change. I wonder if it is just  
a bug related to tables. I almost never use a table anymore now that  
I’ve learned css.

best of luck,  
jp

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [February 28, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/3 "2007-02-28T23:12:33Z")

</div>

Thanks for your reply.

On Wed, Feb 28, 2007 at 05:07:46PM +0100, Jeff P. wrote :

> This looks perfectly correct to me. I do something similar but with an  
> unordered list, and div’s around each of the
> 
> - lines. replace\_html  
> cleanly replaces just the line I want to change.

I have the same snippet for lists too and it works actually.

> I wonder if it is just a bug related to tables.

Maybe. I’m waiting for other replies before going deeper in this problem  
to see where’s the bug. I’m wondering if it is due to the ‘form’ fields.

> I almost never use a table anymore now that I’ve learned css.

Actually, I have an application displaying a whole bunch of data (think  
of  
thousands rows/columns of structured data). So tabulars are perfect for  
me 🙂

Have fun,

–  
pam

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [September 17, 2007, 1:20pm UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/4 "2007-09-17T13:20:23Z")

</div>

\<%= render :partial =\> 'yes' %\>

the above is not valid html. applying your partial, it’s even more  
invalid.

 ... 

that’s not going to work and your browser will screw up the rendering,  
but you already know that.

try:

\<%= render :partial =\> 'yes' -%\>

And the partial yes:  
\<% if @ruby -%\>

bla bla bla ../.. \<% end -%\>

rjs stays the same

keep in mind the # of td’s in your partial should be the same as the  
rest of the table, or have a colspan attribute.

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [March 2, 2007, 2:04am UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/5 "2007-03-02T02:04:15Z")

</div>

Hi Pierre,

Pierre-Alexandre M. wrote:

> > I wonder if it is just a bug related to tables.
> 
> Maybe. I’m waiting for other replies before going deeper in this problem  
> to see where’s the bug. I’m wondering if it is due to the ‘form’ fields.

It’s not a bug with tables. Ajax works on XHTML DOM elements. Tables  
use a  
different DOM. The explanation of the situation is on MSDN. If you’re  
going to use Ajax, you’re either going to use CSS, or you’re going to  
end up  
with some very ugly code because

's can’t be updated / replaced. If  
you  
really need to use tables, the best way I’ve heard of is to replace your

|
| |
|
| |

structure with

|
| |
|
| |

It seems you can do a page.replace on a

. I haven’t tried it.  
My  
recommendation is to bite the bullet and learn a little CSS. You can  
use  
absolute positioning on an - to get the table effect very easily,  
your  
code will be lots cleaner, and you can style the result in ways you’ll  
never  
be able to with a table. OTOH, I hear the XHTML DOM is going to be  
extended  
and CSS3.x is going to include tables. If you can wait 😉

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/6 "2007-09-25T23:09:58Z")

</div>

On Wed, Feb 28, 2007 at 08:34:31AM -0500, Chris H. wrote :

> try:
> 
> \<%= render :partial =\> 'yes' -%\>

It works! Thanks a lot!

> keep in mind the # of td’s in your partial should be the same as the  
> rest of the table, or have a colspan attribute.

Actually the colspan was already there 😉

Have fun,

–  
,========================.  
| Pierre-Alexandre M. |  
| email : removed\_email\_address@domain.invalid |  
`========================’

---

<div class="post-metadata">

**Author:** ![Pierre-Alexandre\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@Pierre-Alexandre\_M](https://www.ruby-forum.com/u/Pierre-Alexandre_M)\
**Post date:** [September 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/ajax-weird-display/87120/7 "2007-09-25T23:05:34Z")

</div>

On Wed, Feb 28, 2007 at 07:12:45PM -0600, Bill W. wrote :

> Hi Pierre,

Hi!

> It seems you can do a page.replace on a
> 
> . I haven’t tried it.
> 
> Unfortunately, it doesn’t work either :’( I will forget about this AJAX  
> trick.
> 
> > My recommendation is to bite the bullet and learn a little CSS. You can use  
> > absolute positioning on an
> > 
> > - to get the table effect very easily, your  
> > code will be lots cleaner, and you can style the result in ways you’ll never  
> > be able to with a table.
> 
> You’re probably right, but at this point on I don’t have the time to  
> learn  
> CSS and replace the 200 tables of my application 😉 Maybe in the RC2…
> 
> > OTOH, I hear the XHTML DOM is going to be extended  
> > and CSS3.x is going to include tables. If you can wait 😉
> 
> I’m pretty sure my customers can’t wait!
> 
> Thanks for your explanation,
> 
> ++
> 
> –  
> ,========================.  
> | Pierre-Alexandre M. |  
> | email : removed\_email\_address@domain.invalid |  
> `========================’
