ソースとかコメントとか

text_fieldのオプションって何使えるんだっけ
みたいなときは、下記順でやってる。


手元の本をめくる
Ruby on Railsで検索
グーグル先生に軽く相談


でも、すぐみつかんなかったのでソースを見てみた。
ソースの場所はRuby on Railsで「Source: show」をクリックすればすぐ見つかる。

 84       # Creates a standard text field; use these text fields to input smaller chunks of text like a username
 85       # or a search query.
 86       #
 87       # ==== Options
 88       # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
 89       # * <tt>:size</tt> - The number of visible characters that will fit in the input.
 90       # * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter.
 91       # * Any other key creates standard HTML attributes for the tag.
 92       #
 93       # ==== Examples
 94       #   text_field_tag 'name'
 95       #   # => <input id="name" name="name" type="text" />
 96       #
 97       #   text_field_tag 'query', 'Enter your search query here'
 98       #   # => <input id="query" name="query" type="text" value="Enter your search query here" />
 99       #
100       #   text_field_tag 'request', nil, :class => 'special_input'
101       #   # => <input class="special_input" id="request" name="request" type="text" />
102       #
103       #   text_field_tag 'address', '', :size => 75
104       #   # => <input id="address" name="address" size="75" type="text" value="" />
105       #
106       #   text_field_tag 'zip', nil, :maxlength => 5
107       #   # => <input id="zip" maxlength="5" name="zip" type="text" />
108       #
109       #   text_field_tag 'payment_amount', '$0.00', :disabled => true
110       #   # => <input disabled="disabled" id="payment_amount" name="payment_amount" type="text" value="$0.00" />
111       #
112       #   text_field_tag 'ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => "ip-input"
113       #   # => <input class="ip-input" id="ip" maxlength="15" name="ip" size="20" type="text" value="0.0.0.0" />
114       def text_field_tag(name, value = nil, options = {})
115         tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
116       end


思ったよりコメントが充実してるんですね。