Params becoming mangled after failed form validation and resubmit

Dear all,
I’m having a weird problem with a fairly straightforward form.
(Please—if this is an RTFM issue, just let me know. I’ve been
looking for answers to no avail, but it’s certainly possible I missed
something.) So:

The software is designed to accept grant applications from libraries,
referred to as “apps”. The various parts of the application—primary
contact info, text descriptions, branch libraries—are resources
nested under apps. Our URLS look pretty normal, e.g.:

hostname/apps/:app_id/branches/:branch_id

I have a form designed to accept address, contact, etc. information
for a branch library, and an optional partner organization. An app
has_many branches. The branches and partners are separate models,
where a branch has_one partner, and a partner belongs_to a branch,
through a polymorphic association. Data for both is taken in through
a single form, run by the branches controller. The branch model has
an accepts_nested_attributes_for :partner call, and the form uses
fields_for partner.

Everything works fine, except for one specific condition: when
creating a new branch record and the partner organization fields fail
validation. The form will reload and display validation errors, as
expected. However, when the form is submitted the second time,
(regardless of whether the problem is fixed) instead of the request
going to the branches controller, (“BranchesController#create”) it
goes to the apps controller, with the app_id passed as the action.
(e.g., “AppsController#7”) Sure enough, it looks like something weird
is happening to params. Here are the params for the first request,
which fails validation:

{“partner”=>{“city”=>"", “addr2”=>"", “zip”=>"", “title”=>“qasdfasd”,
“libtype”=>"", “lname”=>“narf”, “fname”=>“narf”, “libname”=>"",
“email”=>“sfasdf”, “state”=>""},

“authenticity_token”=>“VbxQ+wraZr0SA0kzjhZluhLFMDOXH7wX0Qrcd1RIS2o=”,

“action”=>“create”,

“branch”=>{“addr1”=>"", “city”=>"", “ao_fname”=>"", “ao_title”=>"",
“addr2”=>"", “zip”=>"", “title”=>“asdfsd”, “libtype”=>“Special”,
“lname”=>“branch”, “fname”=>“yet another”, “memnum”=>“sdasd”,
“phone”=>"", “fax”=>"", “partnered”=>“true”, “libname”=>“foo!”,
“state”=>"", “email”=>"", “ao_lname”=>""},

“controller”=>“branches”,

“save”=>“Save Application”,

“app_id”=>“7”,

“_”=>""}

After failed validation, correction and resubmit:

{“partner”=>{“city”=>"", “zip”=>"", “addr2”=>"", “libtype”=>"",
“title”=>“qasdfasd”, “lname”=>“narf”, “fname”=>“narf”,
“libname”=>“foo!”, “state”=>"", “email”=>“sfasdf”},

“authenticity_token”=>“VbxQ+wraZr0SA0kzjhZluhLFMDOXH7wX0Qrcd1RIS2o=”,

“id”=>“branches”,

“branch”=>{“ao_title”=>"", “ao_fname”=>"", “city”=>"", “addr1”=>"",
“zip”=>"", “addr2”=>"", “libtype”=>“Special”, “title”=>“asdfsd”,
“lname”=>“branch”, “memnum”=>“sdasd”, “fname”=>“yet another”,
“partnered”=>“true”, “fax”=>"", “phone”=>"", “libname”=>“foo!”,
“ao_lname”=>"", “email”=>"", “state”=>""},

“save”=>“Save Application”,

“_”=>""}

Note that there is no :controller, no :app_id and no :action;
“branches” should be the value of :controller, but it has now become
the value of :id. I assume I must be doing something dumb in building
the request, but it’s weird that it works if validation passes but not
if it doesn’t. In either case, it’s the same form calling
BranchesController#create; the controller simply tests for the success
of the write and either renders the form again or not.

Any help you can provide would be most enlightening. Please let me
know if there’s other relevant code—I figured for now, this is long
enough as is.

Cheers,
-Erik

What does the log show for the URL in the second request? I’m thinking
you may not be POSTing to the right place…

–Matt J.