public Method

FormTagHelper.text_area_tag(name, content = nil, options = {})

Contents:

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.
  • Any other key creates standard HTML attributes for the tag.

Examples

text_area_tag 'post'
# => <textarea name="post"></textarea>

text_area_tag 'bio', @user.bio
# => <textarea name="bio">This is my biography.</textarea>

text_area_tag 'body', nil, :rows => 10, :cols => 25
# => <textarea name="body" rows="10" cols="25"></textarea>

text_area_tag 'body', nil, :size => "25x10"
# => <textarea name="body" rows="10" cols="25"></textarea>

text_area_tag 'description', "Description goes here.", :disabled => true
# => <textarea name="description" disabled="disabled">Description goes here.</textarea>

text_area_tag 'comment', nil, :class => 'comment_input'
# => <textarea name="comment"></textarea>

Source Code

# File action_view/helpers/form_tag_helper.rb, line 252
def text_area_tag(name, content = nil, options = {})
  options.stringify_keys!

  if size = options.delete("size")
    options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
  end

  content_tag :textarea, content, { "name" => name, "id" => name }.update(options.stringify_keys)
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.