Friday, November 4, 2011

Specifying miscellaneous attributes in a Rails text field

Quick code tip: Specifying miscellaneous attributes in a Rails text field is easy.

Here's an example in which you set autocomplete="off":

<%= text_field_tag 'textfield', nil, :autocomplete=>"off" %>

The idea is to use "nil" as a placeholder for the middle value. In this case, the middle value for text_field_tag is value, which is what normally fills the text field.

If you didn't specify nil as a placeholder for the function, you would get a text field that said {:autocomplete=>"off"} inside. Probably something to avoid :)

No comments:

Post a Comment

Please be considerate in what you say.