# Ajax form submission and updating multiple divs

**URL:** <https://www.ruby-forum.com/t/ajax-form-submission-and-updating-multiple-divs/65472>\
**Category:** Rails\
**Created:** [February 10, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/ajax-form-submission-and-updating-multiple-divs/65472 "2006-02-10T17:02:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 10, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/ajax-form-submission-and-updating-multiple-divs/65472/1 "2006-02-10T17:02:21Z")

</div>

I’m not sure if this is even possible, but here is my current method:

class Item \< ActiveRecord::Base

def self.generate(name)  
Item.create(:name =\> name) || nil  
end  
end

class ItemController \< ActionController::Base

layout “application”

def index  
@items = Item.find(:all)  
end

def create  
if @request.method ==:post  
name = @params[:name] || ‘’  
if name != ‘’  
if Item.generate(name)  
@message = “success”  
else  
@message = “failed”  
end  
else  
@message = “please enter a value”  
end  
@items = Item.find(:all)  
render(:partial =\> “itemlist”)  
end  
end  
end

index.rhtml

\<%= form\_remote\_tag(:update =\> “itemlist”, :url =\> { :action =\> :create  
})  
%\>  
\<label for “name”\>Enter Item Name:  
\<%= text\_field\_tag :name %\>  
\<%= submit\_tag “Save Item” %\>  
\<%= end\_form\_tag %\>

\<%= render(:partial =\> "itemlist") %\>

\_itemlist.thtml

\<%= @message %\>

\<% @items.each do |i| %\> \<% end %\>

| ID | Barcode | created |
| --- | --- | --- |
| \<%= i.id %\> | \<%= i.barcode %\> | \<%= i.created\_at %\> |

now, what i would like to do is separate out the message and table into  
2  
divs. after submitting, if there is a failure, only update the message  
div  
with success/failure message and leave the list div alone. if there was  
success, update both divs with the necessary info. currently, i update  
the  
div for every submission, incurring a hit to the item table to generate  
a  
list whether the submission was successful or not. is there a way to  
accomplish what i would like to do?

Chris
