Render, partial, and cancel button issues

I am using a form_remote_tag to create a new object in my web page.

When the save is successful, then it displays the list and added current
object in a partial.

I have two questions:

  1. When the save fails, i want it to just revert back to the original
    list, and close the form that allows users to add new objects.

  2. I would like my Cancel button on creating this new object to work,
    presently I can close the form, but then I get a MIssing Template
    message in the screen, or with some hacking, the objects list duplicates
    itself in the render.

:- so on this 2nd point, I want to know how to escapoe the render and
revert back to the main list, on when first entering the page. I have
tried :render and :redirect_to but this just duplicates the list again
in the same page.

MY CONTROLLER:

create a new product

def create
@products = Product.find(:all)
@product = Product.new(params[:product])
if @product.save
render :partial => ‘product’
else
redirect_to :action => ‘list’, :id => @product
end
end

MY VIEW:

Products

    <% @products.each do |p| %>
  • <%= link_to p.title, :action => 'show_versions', :id => p.id %> <%= "(#{p.versions.count})" -%>
  • <%= link_to 'Edit', {:action => 'edit', :id => p.id} %> <%= link_to "Delete", {:action => 'delete', :id => p.id}, :confirm => "Are you sure you want to delete this product?" %> <% end %>

<%= link_to_function("Add a new Product", 'Element.show(add_product)')%>

<%= form_remote_tag(:url => {:action => 'create'}, :update => "product_list", :position => :bottom, :html => {:id => 'product_list'})%>

Name: <%= text_field "product", "title" %>

Description: <%= text_area "product", "description", :size => "30x10" %>

<%= submit_tag 'Add', :onclick=> 'Element.hide(add_product)' %> <%= button_to 'Cancel', :onclick=> 'Element.hide(add_product)' %>

Even some suggestions would be great, because googling this issue,
doesnt really churn up much.