Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#3248

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?

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

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Raf
    Raf

    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).

    January 31st, 2010 @ 08:48 AM

  2. Jatinder Singh
    Jatinder Singh

    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
    
    
    

    January 31st, 2010 @ 09:37 AM

  3. Ryan Bigg
    Ryan Bigg
    • 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.

    June 12th, 2010 @ 03:20 AM