Skip to content

Unable to supply nil value to name attribute #808

mhuggins opened this Issue Feb 23, 2012 · 5 comments

3 participants


When using a faux model, I should be able to create an input element that does not have a name attribute. In plain old Rails, I can do this via:

text_field_tag(:username, nil, :name => nil)
# <input id="username" type="text"/>

Unfortunately, this nil value seems to be getting overridden when trying to accomplish the same with Formtastic:

<%= f.input :username, :as => :string, :html_input => {:id => 'username', :name => nil} %>
# <input id="username" name="user[username]" type="text">

Am I missing something, or is there some options.merge happening somewhere that is overwriting (or not assigning) my value of nil? (I also tried using false with no luck.)


text_field_tag is not comparable to anything in Formtastic. A better comparison is f.text_field, which is the form builder version, which means it's bound to the form object. Formtastic is a FormBuilder, thus bound to an object. Incidentally, you can still use both text_field_tag and f.text_field within the Formtastic DSL, but to answer your question...

If you really want no name attribute:

  1. I think :html_input should be :input_html in your example, but if that's just a typo...
  2. I thought your sample would have worked, but if it doesn't (sounds like we're merging options somewhere a little too aggressively)...
  3. Perhaps a blank string would work (:name => ""), or else
  4. Please send a patch :)

That was just a typo, sorry. ;) I gave empty string a try, and that is good enough for my needs as a workaround, even though it still generates the name="" in the HTML. Thanks!


Also, after digging into it. f.text_field has the same behavior as Formtastic in this regards, so I guess it's not a Formtastic issue, sorry! :)

nashby commented Feb 23, 2012


nashby commented Feb 24, 2012

Fixed in rails. ❤️

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.