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:</label>
<%= text_field_tag :name %>
<%= submit_tag "Save Item" %>
<%= end_form_tag %>
<div id="itemlist">
<%= render(:partial => "itemlist") %>
</div>
_itemlist.thtml
<%= @message %>
<table border="1">
<tr>
<th>ID</th>
<th>Barcode</th>
<th>created</th>
</tr>
<% @items.each do |i| %>
<tr>
<td><%= i.id %></td>
<td><%= i.barcode %></td>
<td><%= i.created_at %></td>
</tr>
<% end %>
</table>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060210/bd88e117/attachment.html