This project is archived and is in readonly mode.

#3248 ✓resolved
Matthew Ford

form_for @object generating the wrong url if there is a rollback

Reported by Matthew Ford | September 22nd, 2009 @ 02:45 PM

In a transaction if rollback occurs in my create action and I re-render the new form, the second submit is sent to update not create. The method form_for is generating is a POST to /resource/:id not /resource. perhaps it should check if it's a new_record?

Comments and changes to this ticket

  • Raf

    Raf January 31st, 2010 @ 08:48 AM

    Post request to a specific route (one specified by an id) will trigger the update action. The create action is triggered by a post request to a non-specific route (/resources instead of /resources/:id).

  • Jatinder Singh

    Jatinder Singh January 31st, 2010 @ 09:37 AM

    Well actually it does check for new_record?, checkout following snippet from rails/actionpack/lib/action_view/helpers/form_helper.rb

    @@@ html_options =

          if object.respond_to?(:new_record?) && object.new_record?
            { :class  => dom_class(object, :new),  :id => dom_id(object), :method => :post }
          else
            { :class  => dom_class(object, :edit), :id => dom_id(object, :edit), :method => :put }
          end
    
    
    
  • Ryan Bigg

    Ryan Bigg June 12th, 2010 @ 03:20 AM

    • State changed from “new” to “resolved”

    I think this would only generate this if the record was actually saved, which is the case in a rollback because the object you create isn't going to be magically deleted by SQL. Attempt to reload the object (the method is reload) and rescue that by returning Model.new.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages