Method: ActionView::Helpers::FormTagHelper#text_area_tag
- Defined in:
- actionview/lib/action_view/helpers/form_tag_helper.rb
#text_area_tag ⇒ Object
Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.
Options
-
:size- A string specifying the dimensions (columns by rows) of the textarea (e.g., “25x10”). -
:rows- Specify the number of rows in the textarea -
:cols- Specify the number of columns in the textarea -
:disabled- If set to true, the user will not be able to use this input. -
:escape- By default, the contents of the text input are HTML escaped. If you need unescaped contents, set this to false. -
Any other key creates standard HTML attributes for the tag.
Examples
textarea_tag 'post'
# => <textarea id="post" name="post"></textarea>
textarea_tag 'bio', @user.bio
# => <textarea id="bio" name="bio">This is my biography.</textarea>
textarea_tag 'body', nil, rows: 10, cols: 25
# => <textarea cols="25" id="body" name="body" rows="10"></textarea>
textarea_tag 'body', nil, size: "25x10"
# => <textarea name="body" id="body" cols="25" rows="10"></textarea>
textarea_tag 'description', "Description goes here.", disabled: true
# => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
textarea_tag 'comment', nil, class: 'comment_input'
# => <textarea class="comment_input" id="comment" name="comment"></textarea>
425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'actionview/lib/action_view/helpers/form_tag_helper.rb', line 425 def textarea_tag(name, content = nil, = {}) = .stringify_keys if size = .delete("size") ["cols"], ["rows"] = size.split("x") if size.respond_to?(:split) end escape = .delete("escape") { true } content = ERB::Util.html_escape(content) if escape content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update() end |