# HTML class or id for form\_tag's

**URL:** <https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171>\
**Category:** Rails\
**Created:** [November 4, 2007, 9:22am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171 "2007-11-04T09:22:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [November 4, 2007, 9:22am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171/1 "2007-11-04T09:22:21Z")

</div>

I need my forms to have HTML id or class but seems there is not such  
parameter in form\_tag or form\_tag\_for. At least not in the rails doc.  
I’ve been searching for a while and I couldn’t find a workarround  
without pure HTML or gsub! which wouldn’t be pretty.

Thanks.

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [November 4, 2007, 9:40am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171/2 "2007-11-04T09:40:42Z")

</div>

Macario O. wrote:

> I need my forms to have HTML id or class but seems there is not such  
> parameter in form\_tag or form\_tag\_for. At least not in the rails doc.  
> I’ve been searching for a while and I couldn’t find a workarround  
> without pure HTML or gsub! which wouldn’t be pretty.
> 
> Thanks.

in

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000607](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000607)

is written

form\_tag(â€™/posts/1â€™, :method =\> :put)

# output -

so, try doing (untested)

form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )

# output -

and u should be good.  
hth

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [November 4, 2007, 9:42am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171/3 "2007-11-04T09:42:37Z")

</div>

> so, try doing (untested)
> 
> form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )
> 
> # output -

oops, i meant

form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )

# output -

🙂

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [November 4, 2007, 10:11am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171/4 "2007-11-04T10:11:54Z")

</div>

Shai R. wrote:

> > so, try doing (untested)
> > 
> > form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )
> > 
> > # output -
> 
> oops, i meant
> 
> form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )
> 
> # output -
> 
> 🙂

Thaks for the quick reply. I’ve tried this with form\_remote:

\<% form\_remote\_for( :comentario, :url =\> comentario\_path(@comentario),  
:html =\> { :method =\> :put }, :update =\> @id.to\_s, :id =\> :fade\_out ) do  
|f| %\>

and this

\<% form\_remote\_for( :comentario, :url =\> comentario\_path(@comentario),  
:html =\> { :method =\> :put, :id =\> :fade\_out }, :update =\> @id.to\_s, )  
do |f| %\>

and doesn’t work

you should be able to specify the html id and class for every rendered  
element. Any workarround for form\_remote\_for, link\_to\_remote or every  
other element?

appending gsub!(/^(\<.\*) /, ‘\</1 id=“wathever”’ or something similar to  
the expression return should do but doesn’t looks too good.

---

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [November 8, 2007, 9:46am UTC](https://www.ruby-forum.com/t/html-class-or-id-for-form-tags/119171/5 "2007-11-08T09:46:51Z")

</div>

Shai R. wrote:

> > so, try doing (untested)
> > 
> > form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )
> > 
> > # output -
> 
> oops, i meant
> 
> form\_tag(â€™/posts/1â€™, :id =\> :id\_name, :class=\> :class\_name )
> 
> # output -
> 
> 🙂

Yep, you where right, sorry. This works:

:html =\> { :method =\> :put, :style =\> “float:right;”}

thanks
