# Params becoming mangled after failed form validation and resubmit

**URL:** <https://www.ruby-forum.com/t/params-becoming-mangled-after-failed-form-validation-and-resubmit/174097>\
**Category:** Rails\
**Created:** [August 20, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/params-becoming-mangled-after-failed-form-validation-and-resubmit/174097 "2009-08-20T19:04:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Cameron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2acd7d/32.png) [@Erik\_Cameron](https://www.ruby-forum.com/u/Erik_Cameron)\
**Post date:** [August 20, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/params-becoming-mangled-after-failed-form-validation-and-resubmit/174097/1 "2009-08-20T19:04:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Erik\_Cameron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2acd7d/32.png) [@Erik\_Cameron](https://www.ruby-forum.com/u/Erik_Cameron)\
**Post date:** [August 21, 2009, 5:06pm UTC](https://www.ruby-forum.com/t/params-becoming-mangled-after-failed-form-validation-and-resubmit/174097/2 "2009-08-21T17:06:57Z")

</div>

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.
