# Generated html not sortable?

**URL:** <https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490>\
**Category:** rubyonrails-talk\
**Created:** [June 11, 2008, 12:42pm UTC](https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490 "2008-06-11T12:42:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DAZ](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DAZ](https://discuss.rubyonrails.org/u/DAZ)\
**Post date:** [June 11, 2008, 12:42pm UTC](https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490/1 "2008-06-11T12:42:59Z")

</div>

Hi,

I'm using the rails sortable\_element helper on a list and after it has been sorted I have used this code: &nbsp;&nbsp;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://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DAZ](https://discuss.rubyonrails.org/u/DAZ)\
**Post date:** [June 11, 2008, 5:53pm UTC](https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490/2 "2008-06-11T17:53:37Z")

</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 \<li\> and if I use replace\_html, the original \<li\> stays there. The problem with this approach is that the generated html is a bit rubbish - there will be a nested \<li\> inside the original \<li\> and they will both have the same id.

Is this acceptable or is there a better/correct way of doing this?

cheers,

DAZ

---

<div class="post-metadata">

**Author:** ![DAZ](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DAZ](https://discuss.rubyonrails.org/u/DAZ)\
**Post date:** [June 11, 2008, 9:15pm UTC](https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490/3 "2008-06-11T21:15:00Z")

</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:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [June 12, 2008, 2:34am UTC](https://discuss.rubyonrails.org/t/generated-html-not-sortable/30490/4 "2008-06-12T02:34:05Z")

</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 \<ol\> or \<ul\> surrounding your \<li\>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 \<script\> 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
