# Render, partial, and cancel button issues

**URL:** <https://www.ruby-forum.com/t/render-partial-and-cancel-button-issues/162089>\
**Category:** Rails\
**Created:** [March 5, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/render-partial-and-cancel-button-issues/162089 "2009-03-05T17:17:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskaggs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bskaggs](https://www.ruby-forum.com/u/bskaggs)\
**Post date:** [March 5, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/render-partial-and-cancel-button-issues/162089/1 "2009-03-05T17:17:34Z")

</div>

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.
