Forum: Ruby on Rails escaping [ ]

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
671c6ee4293e03770d6d3a24e8dfc39c?d=identicon&s=25 spokra (Guest)
on 2009-05-27 18:48
(Received via mailing list)
I need a label tag that is like this..

<label class="menulogin" for="user_session[password]">Password</label>

how do i escape it in the label_tag?

 <%= label_tag 'user_session\[password\]', 'Password', :class =>
'menulogin' %>

I keep getting _ for [ and ]
4e4730caefa10a75dc6ba2e3d50ccbad?d=identicon&s=25 Steven Hilton (mshiltonj)
on 2009-05-27 20:28
(Received via mailing list)
On Wed, May 27, 2009 at 12:47 PM, spokra <> wrote:
> I keep getting _ for [ and ]

Internally, label_tag is calling content_tag, but it is sanitizing the
name you pass in.  Intuitively, your snippet should work. I don't know
why the label_tag method is mucking it up.

But, you can bypass label_tag() and go straight to content_tag() and
get what you expect with:

<%= content_tag(:label, "Password", {:for => 'user_session[password]',
:class => "menulogin"}) %>

Steven Hilton <>
This topic is locked and can not be replied to.