Forum: Ruby on Rails Render, partial, and cancel button issues....

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bradley S. (Guest)
on 2009-03-05 18:17
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.

  # create a new product
  def create
    @products = Product.find(:all)
    @product =[:product])
          render :partial => 'product'
          redirect_to :action => 'list', :id => @product

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


<p id='add_link'><%= link_to_function("Add a new Product",

<div id='add_product' style="display:none;">
  <%= form_remote_tag(:url => {:action => 'create'},
        :update => "product_list", :position => :bottom,
         :html => {:id => 'product_list'})%>
      <p>Name: <%= text_field "product", "title" %> </p>
      <p>Description: <%= text_area "product", "description", :size =>
"30x10" %></p>
    <%= 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.
This topic is locked and can not be replied to.