Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Is :namespace supposed to change field names? #651

Closed
DaveSanders opened this Issue · 2 comments

2 participants

@DaveSanders

I have two forms on the same page with (potentially) the same object driving both. (a bill to / same as other address situation) I use :namespace=>billing on the second form and it half works:

<li class="string input required stringish" id="billing_property_name_input">
<label class=" label" for="billing_property_name">Billing Name<abbr title="required">*</abbr></label>
<input id="billing_property_name" maxlength="255" name="property[name]" required="required" size="20" type="text">
</li>

as you see, the input is prefixed with billing in the "id" attribute, but not the "name" attribute. Jquery's serializeArray() looks at the name attribute, so my form params are coming back as params[:property][:name], and since the second form is hidden and filled with blanks, this means my data is blank also.

Shouldn't :namespace also change the field name attribute? Or do I need to do that manually? Or am I just confused? :)

@justinfrench

Hi, namespace was added to address the potential for multiple HTML elements on the page to have the same DOM id, which would cause an invalid document. I don't see any real problem extending this to the name attribute etc, but I think in this case Rails already provides an :as option on form_for. Could you look not that and see if it solves your problem?

@DaveSanders

You are completely right. :as works perfectly. Sorry about that, that's two strikes against me on reporting issues now. I'm going to have to think carefully before I use my last wish. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.