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.