# Noob needs help updating a sortable table in the database

**URL:** <https://www.ruby-forum.com/t/noob-needs-help-updating-a-sortable-table-in-the-database/152888>\
**Category:** Rails\
**Created:** [November 9, 2008, 4:46am UTC](https://www.ruby-forum.com/t/noob-needs-help-updating-a-sortable-table-in-the-database/152888 "2008-11-09T04:46:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeMSak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@JoeMSak](https://www.ruby-forum.com/u/JoeMSak)\
**Post date:** [November 9, 2008, 4:46am UTC](https://www.ruby-forum.com/t/noob-needs-help-updating-a-sortable-table-in-the-database/152888/1 "2008-11-09T04:46:06Z")

</div>

Hi, I am brand new to Rails and I love it, but I am stuck on something  
I just can’t figure out.

I have table in my database of Pages which are listed in the admin  
view in an HTML table.

Each page has  
ID  
Title  
Content  
Page\_order

The HTML table displays:  
Title  
Page\_order

The HTML table has some jQuery attached to it that allows me to sort  
the rows up and down, and then updates the text inside the Page\_order  
table cells to be in numerical order. In other words:

* * *

## | Title | Page Order |

## | About | 0 | | Contact | 1 | | Pricing | 2 |

Say you want Contact to be at the bottom (since the nav menu on the  
web site is ordered by page\_order). So you drag Pricing above Contact  
and you’ll see:

* * *

## | Title | Page Order |

## | About | 0 | | Pricing | 1 | | Contact | 2 |

This I can make work. The part I don’t know how to do is send an ajax  
request to update the database and change the page\_order values to  
reflect the changes.

Can someone help?

---

<div class="post-metadata">

**Author:** ![JoeMSak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@JoeMSak](https://www.ruby-forum.com/u/JoeMSak)\
**Post date:** [November 10, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/noob-needs-help-updating-a-sortable-table-in-the-database/152888/2 "2008-11-10T13:50:36Z")

</div>

Why not defer making changes at the DB level until the person is done  
with the page. Ye olde Save or Cancel (or just navigate away).

An Ajax request and DB update per “fiddle” with a row seems overdone to  
me, but if your interface doesn’t use an explicit “save” button or  
something similar, then it could work.

As for the Ajax part, I haven’t ventured there myself yet.

---

<div class="post-metadata">

**Author:** ![JoeMSak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@JoeMSak](https://www.ruby-forum.com/u/JoeMSak)\
**Post date:** [November 10, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/noob-needs-help-updating-a-sortable-table-in-the-database/152888/3 "2008-11-10T14:22:30Z")

</div>

Well I’m trying to do it from the list action, so there is no save  
button, though I could do that. It’s not a bad idea. Maybe enable/  
reveal a link\_to or button\_to after a change is made?
