# Making a list of records refresh in order after a 'page.inse

**URL:** <https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213>\
**Category:** Rails\
**Created:** [May 27, 2007, 11:49am UTC](https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213 "2007-05-27T11:49:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [May 27, 2007, 11:49am UTC](https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213/1 "2007-05-27T11:49:49Z")

</div>

Hi Everyone,

I’m working through a book that demonstrates using Ajax to add a new  
record to a category. Just a single field, being a name is required.

I’ve applied it to a real app and it works OK except for one small  
detail.

The add facility is on the same page as the list of existing  
categories, & I made one change which is to display the existing  
entries in name order. But when a new one is added it adds to the  
bottom ( which is what it is told to do ), but I want the list to be  
refreshed with the new item in it’s alphabetical position.

The only options for page.insert\_html are: top, bottom, before and  
after.

Here is the ‘new’ def:

def new  
@make = Make.new(params[:make])  
if @make.save  
return if request.xhr?  
render :partial =\> ‘make’, :object =\> @make  
end  
end

Here is the rjs code:

if @make.new\_record?  
page.alert @make.errors.full\_messages.join("\n")  
else  
page.insert\_html :bottom, ‘make\_list’, :partial =\> ‘make’  
page.visual\_effect :highlight, “make\_#{@make.id}”  
page.form.reset ‘make\_form’  
end

( note: The book is using a ‘category’ table where my app is using a  
‘make’ table )

Anyone know how to accomplish this ?

TIA - Dave P.

---

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [May 27, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213/2 "2007-05-27T13:15:59Z")

</div>

You could assign each row (whether it be li, or dd, or tr) with their  
ID, and then in your ruby code find out where it should be, and  
insert below that. The only thing I can think of in these wee hours.

Cheers,  
Zach I.  
â†’ Blog – [http://www.zachinglis.com](http://www.zachinglis.com)  
â†’ Company – [http://www.lt3media.com](http://www.lt3media.com)  
â†’ Portfolio – [http://portfolio.zachinglis.com](http://portfolio.zachinglis.com)

---

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [May 27, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213/3 "2007-05-27T13:42:01Z")

</div>

Thanks Zach,

Sounds a bit complicated for a newbie ! Not life threatening so I’ll  
come back to it.

regards, Dave

---

<div class="post-metadata">

**Author:** ![Davo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@Davo](https://www.ruby-forum.com/u/Davo)\
**Post date:** [September 25, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/making-a-list-of-records-refresh-in-order-after-a-page-inse/105213/4 "2007-09-25T23:02:39Z")

</div>

dear sender,  
i´m out of the office until may 29th.  
your email will not be forwarded.  
for urgent stuff please contact removed\_email\_address@domain.invalid  
kind regards,  
alexander
