# Generated html not sortable?

**URL:** <https://www.ruby-forum.com/t/generated-html-not-sortable/140165>\
**Category:** Rails\
**Created:** [June 11, 2008, 2:44pm UTC](https://www.ruby-forum.com/t/generated-html-not-sortable/140165 "2008-06-11T14:44:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 11, 2008, 2:44pm UTC](https://www.ruby-forum.com/t/generated-html-not-sortable/140165/1 "2008-06-11T14:44:35Z")

</div>

Hi,

I’m using the rails sortable\_element helper on a list and after it has  
been sorted I have used this code:  
page[‘page\_’ + p.id.to\_s].replace :partial =\> ‘page’, :locals =\>  
{ :page =\> p }

to replace the list items that changed order as the html has to  
change.

The problem is that any of the list items that are ‘replaced’ are now  
not sortable. Is this expected behavior and is there a fix or a  
workaround?

thanks,

DAZ

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 11, 2008, 7:54pm UTC](https://www.ruby-forum.com/t/generated-html-not-sortable/140165/2 "2008-06-11T19:54:29Z")

</div>

I’ve found a bit of a hack solution.

If I change replace to replace\_html, it works. I guess that this is  
because the id is in the

- and if I use replace\_html, the original
- stays there. The problem with this approach is that the generated html is a bit rubbish - there will be a nested 
- inside the original 
- Is this acceptable or is there a better/correct way of doing this?

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 11, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/generated-html-not-sortable/140165/3 "2008-06-11T23:15:55Z")

</div>

my ‘hack’ doesn’t work too well, as it introduces loads of problems if  
you then try to sort again as the array that is sent to the sort  
action gets messed up…oh well, it seems that you can’t seem to do  
any JS tricks with generated content.

DAZ

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 12, 2008, 5:23am UTC](https://www.ruby-forum.com/t/generated-html-not-sortable/140165/4 "2008-06-12T05:23:37Z")

</div>

Hi DAZ,

DAZ wrote:

> my ‘hack’ doesn’t work too well, as it introduces loads  
> of problems if you then try to sort again as the array that  
> is sent to the sort action gets messed up…oh well, it  
> seems that you can’t seem to do any JS tricks with  
> generated content.

Have you tried just doing a replace\_html on the

 or 

 surrounding  
your - s? I’ve just been fighting with something that may be related.  
Haven had enough time to isolate the problem further, but when I render  
a  
partial with an observe\_field in it 'normally, the shows up in  
FireBug. When I render the same partial via RJS, it disappears. The  
actions still fire, but I lose the debug ability I so\_much rely on with  
FireBug.

HTH,  
Bill
