# How to modify the html name attribute of a generated input?

**URL:** <https://www.ruby-forum.com/t/how-to-modify-the-html-name-attribute-of-a-generated-input/126411>\
**Category:** Rails\
**Created:** [January 18, 2008, 3:15am UTC](https://www.ruby-forum.com/t/how-to-modify-the-html-name-attribute-of-a-generated-input/126411 "2008-01-18T03:15:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [January 18, 2008, 3:15am UTC](https://www.ruby-forum.com/t/how-to-modify-the-html-name-attribute-of-a-generated-input/126411/1 "2008-01-18T03:15:15Z")

</div>

How can I change the html name attribute of an input? I’ve tried the  
approach used to change the name of a form object:

\<%= text\_field({‘object’, ‘field’}, ‘my\_name’) %\>

But it only added to the name attribute instead of replacing it:

Any idea how I could replace the name attribute completely?

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [January 18, 2008, 8:40am UTC](https://www.ruby-forum.com/t/how-to-modify-the-html-name-attribute-of-a-generated-input/126411/2 "2008-01-18T08:40:23Z")

</div>

Use text\_field\_tag().

p.s. why do you want to break the convention?

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [January 18, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/how-to-modify-the-html-name-attribute-of-a-generated-input/126411/3 "2008-01-18T18:40:57Z")

</div>

Keynan P. wrote:

> Use text\_field\_tag().
> 
> p.s. why do you want to break the convention?

I’m trying to test form automation with www::mechanize. From the syntax  
I’m using (form.field = X), mechanize reads the rails name tags  
incorrectly. In my above example, it reads name=objectfield[namemyname]  
as name=objectfield and can’t find that page element.

text\_field\_tag and select\_tag work wonderfully for setting a name  
attribute and testing this though. Thanks!
